Topic links
Single point update, interval query. The space is so small ....
#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<Set>#include<string>#include<queue>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<1|1#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (I, A, n) for (int i = A; i<n; i++)#defineull unsigned long Longtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Const intMoD = 1e9+7;Const intINF =1061109567;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };Const intMAXN =1050;intsum[maxn*3][maxn*3], N;voidPushup (intPosintRT) {Sum[pos][rt]= sum[pos][rt<<1]+sum[pos][rt<<1|1];}voidSub_update (intSignintPosintPintLintRintRtintval) { if(L = =r) {if(!Sign ) {Sum[pos][rt]+=Val; } Else{Sum[pos][rt]= sum[pos<<1][RT] + sum[pos<<1|1][rt]; } return ; } intm = l+r>>1; if(p<=m) sub_update (sign, POS, p, Lson, Val); Elsesub_update (sign, POS, p, Rson, Val); Pushup (POS, RT);}voidUpdateintXintYintLintRintRtintval) { if(L = =r) {sub_update (0, RT, Y,1N1, Val); return ; } intm = l+r>>1; if(x<=m) update (x, Y, Lson, Val); ElseUpdate (x, Y, Rson, Val); Sub_update (1, RT, Y,1N1, Val);}intSub_query (intPosintLintRintLintRintRT) { if(l<=l&&r>=r) {returnSum[pos][rt]; } intm = l+r>>1, ret =0; if(l<=m) Ret+=sub_query (POS, L, R, Lson); if(r>m) Ret+=sub_query (POS, L, R, Rson); returnret;}intQueryintLxintRxintLyintRyintLintRintRT) { if(lx<=l&&rx>=r) {returnSub_query (RT, Ly, Ry,1N1); } intm = l+r>>1, ret =0; if(lx<=m) Ret+=query (LX, rx, Ly, Ry, Lson); if(rx>m) Ret+=query (LX, rx, Ly, Ry, Rson); returnret;}intMain () {intSign , LX, Ly, Val, Rx, Ry, TMP; while(~SCANF ("%*d%d", &N)) {mem (sum); while(SCANF ("%d", &Sign )) { if(Sign = =3) Break; if(Sign = =1) {scanf ("%d%d%d", &LX, &ly, &val); LX+ +, ly++; Update (LX, LY,1N1, Val); } Else{scanf ("%d%d%d%d", &LX, &ly, &rx, &ry); LX+ +, ly++, rx++, ry++; intAns = query (lx, rx, Ly, Ry,1N1); cout<<ans<<Endl; } } }}
Fafu 1100 Segment Tree