Title Link: http://poj.org/problem?id=1195
Pure two-dimensional tree array, do not explain, just need to pay attention to, because the problem in the array from the beginning of the 0 calculation, so the maintenance time need to add 1. Because the subscript of the tree array is not 1
Code:
#include <iostream> #include <cstdio> #define N 1030using namespace Std;int c[n][n];int cas,n,x,y,a,l,b,r,t; int lowbit (int x) { return x & (-X);} void Updata (int x,int y,int a) { int i,k; For (I=x, i<=n; i+=lowbit (i)) for (k=y; k<=n; k+=lowbit (k)) C[i][k]+=a;} int getsum (int x,int y) { int i,k,sum = 0; For (I=x, i>0; i-=lowbit (i)) for (k=y; k>0; k-=lowbit (k)) sum + = c[i][k]; return sum;} int main () { scanf ("%d%d", &cas,&n); while (~SCANF ("%d", &cas)) { if (cas==1) { scanf ("%d%d%d", &x,&y,&a); Updata (x+1,y+1,a); } if (cas==2) { scanf ("%d%d%d%d", &l,&b,&r,&t); int A=getsum (r+1,t+1)-getsum (l,t+1)-getsum (r+1,b) +getsum (l,b); printf ("%d\n", a); } if (cas==3) return 0; } return 0;}
poj_1195 Mobile Phones "Two-dimensional tree array"