Title Link: http://poj.org/problem?id=1195
Test instructions
give a full 0 matrix, and then some operations0 S: Initialize the matrix, the dimension is s*s, and the value is all 0, this operation only appears at the beginning of the1 X y a: Increase the x, y coordinates of a matrix by a2 L B R T: Ask (l,b) to the sum of the values in the (r,t) interval3: End operation on this matrix"Ideas"Two-dimensional tree array single point update + area query, can be used as a template problem. Note that the coordinates are starting from 0, so take +1 "Code"
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cstdlib>6#include <cmath>7 using namespacestd;8 Const intN =1029;9typedefLong LongLL;Ten intC[n][n], N; One intLowbit (intx) A { - returnX & (-x); - } the voidUpdateintXintYintnum) - { - for(inti = x; I <= N; i + =lowbit (i)) - for(intj = y; J <= N; J + =Lowbit (j)) +C[I][J] + =num; - } + intQueryintXinty) A { at intsum =0; - for(inti = x; i >0; I-=lowbit (i)) - for(intj = y; J >0; J-=Lowbit (j)) -Sum + =C[i][j]; - returnsum; - } in intMain () - { to intI, M; +scanf"%d%d", &i, &n); - while(SCANF ("%d", &m), M! =3) the { * intx1, x2, y1, y2, num; $ if(M = =1)Panax Notoginseng { -scanf"%d%d%d", &x1, &y1, &num); thex1++, y1++; + Update (x1, y1, num); A } the Else + { -scanf"%d%d%d%d", &x1, &y1, &X2, &y2); $x1++, y1++, x2++, y2++; $printf"%d\n", query (x2, y2)-Query (x1-1, y2)-Query (x2, y1-1) + Query (x1-1, Y1-1)); - } - } the return 0; -}
"poj1195" Mobile phones (two-dimensional tree-like array)