问题2291--移动电话(Mobile phones)

2291: 移动电话(Mobile phones)

时间限制: 1 Sec  内存限制: 256 MB
提交: 13  解决: 7
[提交] [状态] [讨论版] [命题人:]

题目描述

Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is 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 is 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 about the current total number of active mobile phones in any rectangle-shaped area.
大意:
假设Tampere地区的4G移动通信基站以如下方式运行。整个地区被划分成若干正方形格子。这些格子构成一个S*S的矩阵,它们的行,列编号都是从0到S-1.每一个格子中都有一个基站。每个格子中激活的手机数量可能改变,因为一部手机可能从一个格子移动到另一个格子,打开或者关闭。有时,某一座基站会向总站报告自己的行列坐标,以及该格中激活手机数目的变化。


输入

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 table matrixsize to S´containing all zeros. This instruction is given only once and it will be the first instruction.

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   结束程序。这个指令只会出现一次,即最后一条指令。



输出

Your program should not answer anything to lines with an instruction other than 2. If the instruction is 2, then your program is expected to answer the query by writing the answer as a single line containing a single integer to standard output.
大意:
你的程序不应该对指令2外的所有指令进行回答。对于每个指令2,你的程序需要输出一行一个正整数,即该指令的答案。

样例输入 Copy

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

样例输出 Copy

3
4

提示

【提示】本题是 IOI2001真题
矩阵大小:1≤S≤1024
任意时刻,每个格子中的激活手机数量V:0≤V≤32767
格子中激活手机数量的变化值:-32768≤A≤32767
输入的指令数目:3≤U≤60002
整个矩阵中的最大手机数量:M=230