Stupid line tree. The memory is small at first.
#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>#defineMAXN 50500using namespacestd;intt,n,tot=0, root,x[maxn],y[maxn],ans=0, hash[maxn],cnt=0, len=0;BOOLVIS[MAXN];intls[maxn<<2],rs[maxn<<2],lazy[maxn<<2];voidBuildint&now,intLeftintRight ) { Now=++tot; if(Left==right)return; intMid= (left+right) >>1; Build (Ls[now],left,mid); Build (Rs[now],mid+1, right); return;}voidModifyintNowintLeftintRightintLintRintx) { if((left==l) && (right==r)) {Lazy[now]=Max (lazy[now],x); return; } intMid= (left+right) >>1; if(r<=mid) Modify (LS[NOW],LEFT,MID,L,R,X); Else if(l>=mid+1) Modify (rs[now],mid+1, right,l,r,x); Else{Modify (ls[now],left,mid,l,mid,x); Modify (Rs[now],mid+1, right,mid+1, r,x); } return;}intAskintNowintLeftintRightintPOS) { if((left==right) && (left==POS)) returnLazy[now]; intMid= (left+right) >>1; if(Pos<=mid)returnMax (Ask (Ls[now],left,mid,pos), Lazy[now]); Else returnMax (Ask (rs[now],mid+1, Right,pos), Lazy[now]);}voidWork () {memset (Vis,false,sizeof(VIS)); memset (lazy,0,sizeof(lazy)); CNT=0; tot=0; len=0; ans=0; scanf ("%d",&N); for(intI=1; i<=n;i++) {scanf ("%d%d",&x[i],&Y[i]); hash[++cnt]=x[i];hash[++cnt]=Y[i]; } sort (Hash+1, hash+cnt+1); Len=unique (hash+1, hash+cnt+1)-hash-1; Build (Root,1, Len); for(intI=1; i<=n;i++) { intL=lower_bound (hash+1, hash+len+1, X[i])-Hash; intR=lower_bound (hash+1, hash+len+1, Y[i])-Hash; Modify (Root,1, Len,l,r,i); } for(intI=1; i<=len;i++) Vis[ask (Root,1, Len,i)]=true; for(intI=1; i<=n;i++) if(Vis[i]) ans++; printf ("%d\n", ans);}intMain () {scanf ("%d",&t); for(intI=1; i<=t;i++) work (); return 0;}
POJ 2528 Mayor ' s posters