Mentioned cdq, would have to mention this damn road, suffer a thousand knives topic.
Minimalist questions surface:
Given a two-dimensional plane, at time ti will put a point (xi, yi), queries in a block which point the number of time tj
See questions is a two-dimensional tree line fucks ah, so the water? ? ?
Discouraging data range warning
Is a one-dimensional array of almost a bit too much ... 1e6 * 1e6's? Several GB? ? ?
。。。
So, the great divide and conquer CDQ played.
In fact, the translation may face problems like this:
Insertion point in time, to ask less than (x, y) and the time point the current point is less than the number
Is not that CDQ thing? Even more than the bare template title. . .
But you may want to look at the difference (two-dimensional differential) because the statistics is the large rectangle consisting of 00 points, so to cut two rectangles, plus a small rectangle, so to count partial order four points
To sum up, it is cdq.
A first time dimension, a second dimension x, y of the third dimension
Be sure to do offline
So began a pleasant CDQ
#include<bits/stdc++.h> using namespace std; const int maxn=505; struct node { int time,x,y,val,id; }e[maxn]; int m,cnt,t[maxn<<1],a[maxn],ans[maxn]; inline int lowbit(int x) { return x & - x ; } void add(int x,int y) { for(;x<=m;x+=lowbit(x)) { t[x]+=y; } } int ask(int x) { int res=0; for(;x;x-=lowbit(x)) { res+=t[x]; } return res; } bool cmp2(node a,node b) { if(a.x!=b.x)return a.x<b.x; if(a.y!=b.y)return a.y<b.y; //else return a.time<b.time; } bool cmp(node a,node b) { return a.time<b.time; } void cdq(int l,int r) { if(l==r)return; int mid=l+r>>1; cdq(l,mid); cdq(mid+1,r); sort(e+l,e+1+r,cmp2); for(int i=l;i<=r;i++) { if(e[i].x<=mid&&e[i].id==0) add(e[i].y,e[i].val); else e[i].val+=ask(e[i].y); } for(int i=l;i<=r;i++) { if(e[i].x<=mid&&e[i].id==0) add(e[i].y,-e[i].val); } } int read() { int f=1,x=0;char s=getchar(); while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();} while(s<='9'&&s>='0'){x=x*10+s-'0';s=getchar();} return x*f; } int main() { read(); m=read(); int flag=read(); while(flag!=3) { if(flag==1) { int x=read()+1,y=read()+1,val=read(); e[++cnt]=(node){cnt,x,y,val,0}; } else { intRead = X1 (), YL = Read (), X2 = Read () + . 1 , Y2 = Read () + . 1 ; E [ ++ CNT] = (Node) {CNT, X1, YL, 0 , . 1 }; // data structure of E [ ++ CNT] = (Node) {CNT, X2, Y2, 0 , . 1 }; E [ ++ CNT] = (Node) {CNT, X2, YL, 0 , . 1 }; E [ ++ CNT] = (Node) {CNT, X1, Y2, 0 , . 1 }; } In Flag = Read (); } cdq ( . 1 , CNT); and hard cdq on the line Sort (E + . 1 , E + + cnt 1,cmp); for(int i=1;i<=cnt;++i) { if(e[i].id==1) { printf("%d\n",e[i].val+e[i+1].val-e[i+2].val-e[i+3].val); i+=3; } } return 0; }
(Finish)