提交时间:2022-07-19 11:51:29

运行 ID: 52274

#include<bits/stdc++.h> using namespace std; struct NODE { int l; int r; }; const int N=5e5+5; int n; NODE line[N]; int c[N]; int len; bool cmp(const NODE& a,const NODE& b) { if(a.l!=b.l)return a.l<b.l; else return a.r>b.r; } int Find(int x) { int l=1,r=len,mid; while(l<=r) { mid=(l+r)/2; if(x<=c[mid])l=mid+1; else r=mid-1; } return l; } int main() { // freopen("game.in","r",stdin); // freopen("game.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;++i) { scanf("%d%d",&line[i].l,&line[i].r); } sort(line+1,line+1+n,cmp); for(int i=1;i<=n;++i) { int k=Find(line[i].r); c[k]=line[i].r; len=max(len,k); } printf("%d\n",len); } /* 20 1 4 4 14 4 11 4 11 5 20 6 7 6 9 7 20 9 19 10 20 12 18 12 18 12 15 13 14 14 14 14 18 18 18 19 19 19 20 20 20 */