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

运行 ID: 52280

#include<bits/stdc++.h> using namespace std; int n,len,f[500005]; pair<int,int>a[500005]; int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second; sort(a+1,a+n+1,less<pair<int,int> >()); for(int i=1;i<=n;i++){ if(len==0||a[i].second<=f[len])f[++len]=a[i].second; else{ int l=1,r=len; while(l<r){ int mid=(l+r)>>1; if(f[mid]>=a[i].second){ l=mid; if(f[mid-1]<a[i].second)break; } else r=mid-1; } f[l]=a[i].second; } } cout<<len<<'\n'; return 0; }