Test instructions: The underlying two-dimensional array, note that 0 + lowbit (0) will fall into an infinite loop-----
Before doing a one-dimensional has been tle, is because of this--------------------------
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=1000005; - - intc[1055][1055]; + intN; - + intLowbit (intx) {returnX & (-x);} A at intSumintXinty) { - intRET =0, y1; - while(X >0){ -Y1 =y; - while(Y1 >0){ -RET + = c[x][y1];y1-=lowbit (y1); in } -x-=lowbit (x); to } + returnret; - } the * voidAddintXintYintd) { $ intY1;Panax Notoginseng while(x <=N) { -Y1 =y; the while(Y1 <=N) { +C[X][Y1] + = D; Y1 + =lowbit (y1); A } theX + =lowbit (x); + } - } $ $ intMain () { - intcmd; - while(SCANF ("%d%d", &cmd,&n)! =EOF) { theMemset (c,0,sizeof(c)); - while(SCANF ("%d", &cmd)! = EOF && cmd! =3){Wuyi if(cmd = =1){ the intx,y,d; -scanf" %d%d%d", &x,&y,&d); x++;y++; Wu Add (x,y,d); - } About Else{ $ intX,y,xx,yy; - intRET =0; -scanf"%d %d%d%d",&x,&y,&xx,&yy); -x++;y++;xx++;yy++; Aret = SUM (xx,yy)-SUM (X-1, yy)-sum (xx,y-1) + SUM (x1, Y1); +printf"%d\n", ret); the } - } $ } the return 0; the}
View Code
Say a few days didn't write the code of said AH----
Come on (^ω^).
Goooooooooooooooooo----
POJ 1195 Mobile Phones "two-dimensional tree-like array"