Total Submissions: 17259 |
|
Accepted: 7962 |
Description Suppose the fourth generation mobile phone base stations in the Tampere area operate as follows. The area was divided into squares. The squares form an s * s matrix with the rows and columns numbered from 0 to S-1. Each square contains a base station. The number of active mobile phones inside a square can change because a phone was moved from a square to another or a phone is switched on or off. At times, each base station reports the change in the number of active phones to the main base station along with the row And the column of the Matrix.
Write a program, which receives these reports and answers queries on the current total number of active mobile phones I N any rectangle-shaped area.
Input the input is read from standard input as integers and the answers to the queries are written to standard output a s integers. The input is encoded as follows. Each input comes to a separate line, and consists of one instruction integer and a number of parameter integers according to the following table.
The values would always have in range and so there are no need to check them. In particular, if A was negative, it can be assumed that it'll not reduce the square value below zero. The indexing starts at 0, e.g. for a table of size 4 * 4, we have 0 <= X <= 3 and 0 <= Y <= 3.
Table size:1 * 1 <= S * S <= * 1024x768
Cell value v at any time:0 <= v <= 32767
Update Amount: -32768 <= A <= 32767
No of instructions in Input:3 <= U <= 60002
Maximum number of phones In the whole table:m= 2^30
Output Your program should isn't answer anything to lines with a instruction other than 2. If the instruction is 2 and then your program was expected to answer the query by writing the answer as a single line Containi Ng a single integer to standard output.
Sample Input
0 4
1 1 2 3
2 0 0 2 2
1 1 1 2
1 1 2-1
2 1 1 2 3
3
Sample Output
3
4
In order to test their own two-bit tree-like array of how to do the water problem appearance without suspense 1A
/************ poj1195 2016.2.1 5024K 954MS g++ ************/#include <iostream> #include <cstdio> #include &
Lt;cstring> using namespace std;
int tree[1050][1050],n,t,x,y,a,l,b,r,cmd;
int lowbit (int i) {return i& (-i),} void update (int x,int y,int a) {for (int i=x;i<=n;)
{for (int j=y;j<=n;)
{tree[i][j]+=a;
J+=lowbit (j);
} i+=lowbit (i);
}} int query (int x,int y) {int s=0;
For (Int. i=x;i>0;i-=lowbit (i)) {for (int j=y;j>0;j-=lowbit (j)) S+=tree[i][j];
} return s;
} int main () {//Freopen ("Cin.txt", "R", stdin);
scanf ("%d%d", &cmd,&n);
memset (tree,0,sizeof (tree));
while (~SCANF ("%d", &cmd)} {if (cmd==3) break;
if (cmd==1) {scanf ("%d%d%d", &x,&y,&a);
x++;y++;
Update (X,Y,A); } else {scanf ("%d%d%d%d", &l,&b,&r,&T);
int sum=0;
l++;b++;r++;t++;
Sum=query (r,t) +query (l-1,b-1)-query (l-1,t)-query (r,b-1);
printf ("%d\n", sum);
}} return 0;
}