Is the overall two points ...
Then we split a rectangular query into four, press X to sort by Y to add a bit and you can do it with O (n * logn^2) ~
1 /**************************************************************2 problem:11763 User:rausen4 language:c++5 result:accepted6 time:4620 Ms7 memory:25808 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <algorithm> A - using namespacestd; - Const intN = 2e6 +5; the Const intQ = 2e5 +5; - - structQuery { - intx, Y, V, W, id, op; + -InlineBOOL operator< (ConstQuery q)Const { + returnx = = q.x? y = = Q.y? Op < q.op:y < Q.y:x <q.x; A } at } Q[q], tmp[q]; - - ints, N, CNT, cnt_query; - intBit[n], ans[n]; - -InlineintRead () { in intx =0, SGN =1; - CharCH =GetChar (); to while(Ch <'0'||'9'<ch) { + if(ch = ='-') SGN =-1; -CH =GetChar (); the } * while('0'<= CH && Ch <='9') { $x = x *Ten+ CH-'0';Panax NotoginsengCH =GetChar (); - } the returnSGN *x; + } A theInlinevoidAdd_add () { +q[++cnt].x = Read (), q[cnt].y = Read (), Q[CNT].V = Read (), q[cnt].id =CNT; - } $ $InlinevoidAdd_query () { - intX1 = Read (), y1 = Read (), x2 = Read (), y2 = Read (), W = + +Cnt_query; -Q[++CNT].W = W, q[cnt].id = cnt, q[cnt].x = x1-1, q[cnt].y = y1-1, Q[CNT].V =1, Q[cnt].op =1; theQ[++CNT].W = W, q[cnt].id = cnt, q[cnt].x = x2, q[cnt].y = y2, q[cnt].v =1, Q[cnt].op =1; -Q[++CNT].W = W, q[cnt].id = cnt, q[cnt].x = x1-1, q[cnt].y = y2, q[cnt].v =-1, Q[cnt].op =1;WuyiQ[++CNT].W = W, q[cnt].id = cnt, q[cnt].x = x2, q[cnt].y = y1-1, Q[CNT].V =-1, Q[cnt].op =1; the } - Wu #defineLowbit (x) x & X -InlinevoidAddintXintd) { About while(x <=N) $BIT[X] + = d, x + =lowbit (x); - } - -InlineintQueryintx) { A intres =0; + while(x) theRes + = Bit[x], X-=lowbit (x); - returnRes; $ } the #undefLowbit the the voidWorkintLintr) { the if(L = = r)return; - intMID = L + R >>1, I, L1, L2; in for(i = l; I <= R; + +)i) { the if(Q[i].id <= mid && Q[i].op = =0) Add (q[i].y, Q[I].V); the if(Q[i].id > Mid && q[i].op) ANS[Q[I].W] + q[i].v *query (Q[I].Y); About } the for(i = l; I <= R; + +)i) the if(Q[i].id <= mid && Q[i].op = =0) Add (Q[I].Y,-q[i].v); the +L1 = L, L2 = mid +1; - for(i = l; I <= R; + +)i) the if(Q[i].id <= mid) tmp[l1++] =Q[i];Bayi Elsetmp[l2++] =Q[i]; the for(i = l; I <= R; ++i) Q[i] =Tmp[i]; theWork (L, mid), work (Mid +1, R); - } - the intMain () { the intOper, I; thes = Read (), n =read (); the while(1) { -Oper =read (); the if(Oper = =1) Add_add (); the Else if(Oper = =2) Add_query (); the Else Break;94 } theSort (q +1, q + cnt +1); theWork1, CNT); the for(i =1; I <= cnt_query; ++i)98printf"%d\n", Ans[i]); About return 0; -}
View Code
BZOJ1176 [Balkan2007]mokia