提交时间:2022-07-19 11:51:11
运行 ID: 52253
#include<map> #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; inline int read(){ int x=0,ch=getchar(); while(ch<48||ch>57) ch=getchar(); while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar(); return x; } int n; struct node{ int l,r; friend bool operator <(node x,node y){ return x.l==y.l?x.r>y.r:x.l<y.l; } }e[500005]; inline int max(int x,int y){return x>y?x:y;} int dp[500005]; int to[500005]; int maxn,bg; int main(){ // freopen("game.in","r",stdin); n=read(); for(int i=1;i<=n;++i){ e[i].l=read(),e[i].r=read(); } sort(e+1,e+n+1); for(int i=1;i<=n;++i){ if(maxn>=e[i].r){ for(int j=bg;j>=1;--j) if(to[j]>=e[i].r){ dp[i]=j; break; } } dp[i]++; bg=max(bg,dp[i]); if(to[dp[i]]<e[i].r) to[dp[i]]=e[i].r; maxn=max(maxn,e[i].r); } printf("%d\n",dp[n]); return 0; }