The input is
read from standard input as integers and the answers to the queries are written
to standard output as integers. The input is encoded as follows. Each input
comes on a separate line, and consists of one instruction integer and a number
of parameter integers according to the following table.
Instruction
|
Parameters
|
Meaning
|
0
|
S |
Initialize the |
1
|
X Y A
|
Add A to the
number of active phones intable square (X, Y). A may be positive
or negative.
|
2
|
L B R T
|
Query the current sum of numbers of active mobile phones in squares (X,Y),
where L £ X £ R, B £ Y £ T
|
3
|
|
Terminate program. This instruction is given only once and it will be the
last instruction.
|
The values will always be in range, so there is no need to check them. In particular, if A is negative, it can be assumed that it will 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.
大意:
输入指令编码如下。
每个指令占一行,包含一个指令码和一些参数,见下表。
指令码 | 参数 | 意义 |
0 | S | 初始化一个S*S的全零矩阵。这个指令只会出现一次,即第一条指令。 |
1 | X Y A | 将格子(X,Y)中激活的手机数量增加A。A有可能是正数或负数。 |
2 | L B R T | 询问当前所有坐标(X,Y)满足:L<=X<=R,B<=Y<=T的格子中激活的手机数量之和。 |
3 | 结束程序。这个指令只会出现一次,即最后一条指令。 |
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
3
4