Jabberwocky (Standard IO)
Time Limits: 2000 ms Memory Limits: 1048576 KB
Sample Input
1
10 3
1 2 3
2 1 1
2 4 2
3 5 3
4 4 2
5 1 2
6 3 1
6 7 1
7 2 3
9 4 2
Sample Output
5
Time Limits: 2000 ms Memory Limits: 1048576 KB
Sample Input
1
10 3
1 2 3
2 1 1
2 4 2
3 5 3
4 4 2
5 1 2
6 3 1
6 7 1
7 2 3
9 4 2
Sample Output
5
Data Constraint
K&N<=100000 , T<=3
枚举不选某种颜色,那么我们需要对一个特点区域求其中点的个数,离散化后,用树状数组套线段树可以Log^2 N实现
#include
#include
#include
#include
#include
using namespace std; const int N=1000010; struct node{ int x,y,z,l,r; }f[N]; node us[N]; set
s,b; int n,m,k,i,j,T,mx,my,tot,ua,ub,da,db; int K[N],hea[N],ro[N]; struct Setree{ int l,r,q; }tr[28900011]; bool cmp(node a,node b){ return( a.y
=r){ tr[p].q++;return; } int m=(l+r)/2; tr[p].q++; if(tar<=m){ if(tr[p].l==0)tr[p].l=++tot; INS(tar,l,m,tr[p].l); }else{ if(tr[p].r==0)tr[p].r=++tot; INS(tar,m+1,r,tr[p].r); } } void ins(int x,int y){ for(int i=x;i<=mx;i+=lowbit(i)){ if(ro[i]==0)ro[i]=++tot; INS( y , 1 , my , ro[i] ); } } int QRY(int tara,int tarb,int l,int r,int p){ int i,j,k,m; if(tara>tarb)return 0; if(!p)return 0; m=(l+r)/2; k=0; if(tara==l&&tarb==r)return tr[p].q; if(tarb<=m){ k=QRY(tara,tarb,l,m,tr[p].l); }else if (tara>m){ k=QRY(tara,tarb,m+1,r,tr[p].r); }else { k=QRY(tara,m,l,m,tr[p].l)+QRY(m+1,tarb,m+1,r,tr[p].r); } return k; } int qry(int x,int y,int ya){ int r=0; for(int i=x;i>0;i-=lowbit(i))r+=QRY(y,ya,1,my,ro[i]); return r; } void discretize(){ sort(f+1,f+1+n,_cmp); int i,j,k; int disva=0,la=0; for(i=1;i<=n;i++)if(f[i].x!=la)la=f[i].x,f[i].x=++disva;else f[i].x=disva; mx=disva; sort(f+1,f+1+n,cmp); la=0;disva=0; for(i=1;i<=n;i++)if(f[i].y!=la)la=f[i].y,f[i].y=++disva;else f[i].y=disva; my=disva; } int col[N]; int main(){ scanf("%d",&T); while(T--){ scanf("%d%d",&n,&k); memset(f,0,sizeof(f)); bool ju[N]; memset(ju,0,sizeof(ju)); int jud=0; memset(col,0,sizeof(col)); for(i=1;i<=n;i++){ scanf("%d%d%d",&f[i].x,&f[i].y,&f[i].z); if(ju[f[i].z]==0)jud++,ju[f[i].z]=1; col[f[i].z]++; } if(jud
f memset(K,0,sizeof(K)); memset(hea,0,sizeof(hea)); memset(ro,0,sizeof(ro)); memset(tr,0,sizeof(tr)); for(i=1;i<=n;i++){ ins(f[i].x,f[i].y); } for(i=1;i<=n;i++){ f[i].l=K[f[i].z]; if(f[i].l)f[f[i].l].r=i; if(K[f[i].z]==0)hea[f[i].z]=i; K[f[i].z]=i; } int ans=0; k++; ua=ub=da=db=0; while(--k){//select colour k if(n-col[k]<=ans)continue; s.clear(); b.clear(); s.insert(0); b.insert(mx+1); int lest=mx,rest=0; int v=0; for(int u=hea[k];u;u=f[u].r){ us[++v]=f[u]; rest=max(rest,f[u].x); lest=min(lest,f[u].x); int xa=-*s.upper_bound(-f[u].x); int xb=*b.upper_bound(f[u].x); xb--; int y=f[u].y-1; s.insert(-f[u].x); b.insert(f[u].x); //in MAINindexTree need to process SIGMA(xb)-SIG(xa) //Limits y int test=qry(xb,1,my)-qry(xa,1,my); if(test
ans)ans=po; } sort(us+1,us+1+v,_cmp); int A=max(qry(lest-1,1,my),n-qry(rest,1,my)); ans=max(A,ans); s.clear(); b.clear(); s.insert(0); b.insert(mx+1); for(int es=2;es<=v;es++){ ans=max(ans,qry(us[es].x-1,1,my)-qry(us[es-1].x,1,my)); } for(int u=K[k];u;u=f[u].l){ int xa=-*s.upper_bound(-f[u].x); int xb=*b.upper_bound(f[u].x); xb--; int y=f[u].y+1; s.insert(-f[u].x); b.insert(f[u].x); int test=qry(xb,1,my)-qry(xa,1,my); if(test
ans)ans=po; } } cout<
<