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

运行 ID: 52263

#include <bits/stdc++.h> using namespace std; #define ll long long template<typename T> inline void Read(T &x) { char ch=getchar(); x=0; while(!isdigit(ch)) ch=getchar(); while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); } struct Node { ll l,r; } a[500010]; ll n,f[500010],len=1; inline void Ef(int i) { #define mid (L+R>>1) int L=1,R=len; while(L<R) { if(f[mid]>=a[i].r) L=mid+1; else R=mid; } f[L]=a[i].r; } int main() { Read(n); for(int i=1; i<=n; i++) Read(a[i].l),Read(a[i].r); f[1]=a[1].r; for(int i=1; i<=n; i++) if(a[i].r<f[len]) f[++len]=a[i].r; else Ef(i); cout<<len<<endl; return 0; }