提交时间:2022-07-19 11:53:15
运行 ID: 52329
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n,cnt,lst,ans,dp,maxn[4*N]; struct wood { int x,y; } a[N]; bool cmp1(wood x,wood y) { if(x.x != y.x) return x.x < y.x; return x.y > y.y; } bool cmp2(wood x,wood y) { return x.y < y.y; } void update(int x,int l,int r,int p,int v) { if(l == r) { maxn[x] = max(maxn[x],v); return ; } if(p <= (l + r) / 2) update(x * 2,l,(l + r) / 2,p,v); else update(x * 2 + 1,(l + r) / 2 + 1,r,p,v); maxn[x] = max(maxn[x * 2],maxn[x * 2 + 1]); } int qmax(int x,int l,int r,int u,int v) { if(u <= l && r <= v) return maxn[x]; int ret = 0; if(u <= (l + r) / 2) ret = qmax(x * 2,l,(l + r) / 2,u,v); if(v > (l + r) / 2) ret = max(ret,qmax(x * 2 + 1,(l + r) / 2 + 1,r,u,v)); return ret; } int main() { scanf("%d",&n); for(int i = 1; i <= n; i++) scanf("%d%d",&a[i].x,&a[i].y); lst = cnt = 0; sort(a + 1,a + n + 1,cmp2); for(int i = 1; i <= n; i++) { if(a[i].y != lst) { lst = a[i].y; cnt++; } a[i].y = cnt; } sort(a + 1,a + n + 1,cmp1); memset(maxn,0,sizeof(maxn)); for(int i = 1; i <= n; i++) { dp = qmax(1,1,cnt,a[i].y,cnt) + 1; update(1,1,cnt,a[i].y,dp); ans = max(ans,dp); } printf("%d\n",ans); return 0; }