Requires that you can calculate the contribution of the previous action to the following question
BZOJ1176
#include <cstdio>#include<algorithm>using namespacestd; inttr[2000001],p,ans[10001],s,q,opt,n,que; structdata1{intpo,x,y,num,v,opt; }a[200001],tmp[200001]; structdata{intNum,po; }yt[200001]; intMyComp (ConstData&a,Constdata&b) { return(a.num<b.num); } intLowbit (intPO) { return(po& (-po)); } intQueryintPO) { intret=0; for(;p o;po-=lowbit (PO)) ret+=Tr[po]; return(ret); } voidAddintPointnum) { for(;p o<=p;po+=lowbit (PO)) tr[po]+=num; } voidSolveintLintR) { if(L==R)return; intMid= (l+r) >>1; Solve (l,mid); Solve (mid+1, R); intpo=l; for(intI=mid+1; i<=r;i++) if(a[i].opt==2){ while(po<=mid&&a[po].x<=a[i].x) { if(a[po].opt==1) Add (a[po].y,a[po].num); PO++; } Ans[a[i].po]+=query (A[I].Y) *a[i].v; } for(inti=l;i<po;i++) if(a[i].opt==1) Add (a[i].y,-a[i].num); intPo1=l,po2=mid+1, po3=l; while(po1<=mid&&po2<=R) { if(a[po1].x<a[po2].x) tmp[po3++]=a[po1++];Elsetmp[po3++]=a[po2++]; } while(Po1<=mid) tmp[po3++]=a[po1++]; while(po2<=r) tmp[po3++]=a[po2++]; for(inti=l;i<=r;i++) a[i]=Tmp[i]; } intMain () {scanf ("%d%d",&s,&q); while(SCANF ("%d", &opt), opt!=3){ if(opt==1) {n++; A[n].opt=1; scanf ("%d%d%d",&a[n].x,&yt[n].num,&a[n].num); Yt[n].po=N; }Else{ intT1,t2,t3,t4; scanf ("%d%d%d%d",&t1,&t2,&t3,&T4); Que++; a[++n].po=que;a[n].v=1; a[n].x=t3;yt[n].num=t4;yt[n].po=n;a[n].opt=2; a[++n].po=que;a[n].v=-1; a[n].x=t1-1; yt[n].num=t4;yt[n].po=n;a[n].opt=2; a[++n].po=que;a[n].v=-1; a[n].x=t3;yt[n].num=t2-1; yt[n].po=n;a[n].opt=2; a[++n].po=que;a[n].v=1; a[n].x=t1-1; yt[n].num=t2-1; yt[n].po=n;a[n].opt=2; }} sort (YT+1, yt+n+1, MyComp); yt[0].num=-1e9; P=0; for(intI=1; i<=n;i++){ if(yt[i].num!=yt[i-1].num) p++; A[yt[i].po].y=p; } Solve (1, N); for(intI=1; i<=que;i++) printf ("%d\n", Ans[i]); }
CDQ Divided treatment