Test instructions: A two-dimensional tree array, changing the value is a little different,
is to set a[x][y] to a value, so add has to make it worse than the previous value.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=5005; - - intA[MAXN][MAXN]; + intC[MAXN][MAXN];//tree-like array - intN; + A intLowbit (intx) {returnX & (-x);} at - intSumintXinty) { - intret=0; - intY1; - while(X >0){ -Y1 =y; in while(Y1 >0){ -RET + = c[x][y1];y1-=lowbit (y1); to } +x-=lowbit (x); - } the returnret; * } $ Panax Notoginseng voidAddintXintYintd) { - intY1; the while(X <MAXN) { +Y1 =y; A while(Y1 <MAXN) { theC[x][y1]+=d; y1+=lowbit (y1); + } -x+=lowbit (x); $ } $ } - - intMain () { the intT; -scanf"%d",&T);Wuyi while(t--){ theMemset (c,0,sizeof(c)); -Memset (A,0,sizeof(a)); Wuscanf"%d",&n); - Chars[ the]; About while(SCANF ("%s", s)! =EOF) { $ if(s[0] =='E') Break; - if(s[1]=='E'){ - intX,y,num; -scanf" %d%d%d", &x,&y,&num); x++;y++; A intTMP = num-A[x][y]; +A[x][y] =num; the Add (x,y,tmp); - } $ if(s[1]=='U'){ the intX,y,xx,yy; the intans=0; thescanf"%d %d%d%d",&x,&y,&xx,&yy); thex++;y++;xx++;yy++; -ans = SUM (xx,yy)-SUM (x1, yy)-sum (xx,y-1) + SUM (x1, Y1); inprintf"%d\n", ans); the } the } About } the return 0; the}
View Code
Spoj 1029 Matrix Summation "Two-dimensional tree-like array"