1532. [IOI2001] Mobile phone
★☆ input file: mobilephones.in output file: mobilephones.out Simple comparison
Time limit: 5 s memory limit:
"Title description"
Assume that the 4G mobile communication base Station in the Tampere region operates as follows. The entire area is divided into several square lattices. These squares form a s*s matrix, with rows and columns numbered from 0 to S-1. There is a base station in each lattice. The number of phones activated in each grid may change, as a cell phone may move from one grid to another, open or close. Sometimes, a base station will report its own row and column coordinates to the terminus, as well as the change in the number of activated phones in that cell.
"Input Format"
The input instruction is encoded as follows.
Each instruction takes on one line, contains a script and some parameters, as shown in the following table.
| Instruction Code |
Parameters |
Significance |
| 0 |
S |
Initializes a s*s full 0 matrix. This command will only appear once, that is, the first instruction. |
| 1 |
X Y A |
Increase the number of phones activated in the lattice (x, y) by a. A is likely to be positive or negative. |
| 2 |
L B R T |
Ask the current all coordinates (x, y) to satisfy: the sum of the number of phones activated in the l<=x<=r,b<=y<=t lattice. |
| 3 |
|
End the program. This command will only appear once, that is, the last instruction. |
"Output Format"
Your program should not answer all instructions outside of command 2. For each instruction 2, your program needs to output a single positive integer, which is the answer to the instruction.
"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
The sample
3
4
Prompted
Matrix Size: 1<=s<=1024
At any moment, the number of activated phones in each lattice v:0<=v<=32767
Change in number of activated phones in lattice: -32768<=a<=32767
Number of instructions entered: 3<=u<=60002
Maximum number of phones in the entire matrix: m=2^30
Source
IOI 2001
Two-dimensional bit maintenance interval and
#include <cstdio>Const intn=3005;intOpt,n,c[n][n];intRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intLowbit (intx) { returnx&-x;}voidUpdata (intXintYintval) { for(inti=x;i<=n;i+=lowbit (i)) { for(intj=y;j<=n;j+=Lowbit (j)) {C[i][j]+=Val; } }}intQueryintXinty) { intres=0; for(inti=x;i>=1; i-=lowbit (i)) { for(intj=y;j>=1; j-=Lowbit (j)) {Res+=C[i][j]; } } returnRes;}intMain () {Freopen ("mobilephones.in","R", stdin); Freopen ("Mobilephones.out","W", stdout); Opt=read (); n=read (); for(intX1,x2,y1,y2,val; (Opt=read ())! =3;){ if(opt==1) {x1=read (); Y1=read (); Val=read (); x1++;y1++; Updata (X1,y1,val); } Else{x1=read (); Y1=read (); x1++;y1++; X2=read (); Y2=read (); x2++;y2++; printf ("%d\n", query (x2,y2)-query (x2,y1-1)-query (x1-1, y2) +query (x1-1, y1-1)); } } return 0;}
COGS1532. [IOI2001] Mobile phone