#P4390. [BalkanOI 2007] Mokia 摩基亚
[BalkanOI 2007] Mokia 摩基亚
Description
The mobile phone company Mokia in Morvado has designed a new user localization system. Like other localization systems, it can quickly answer any question of the form “Where is user C?”, accurate to the millimeter. But its truly high-tech feature is that it can answer questions like “How many users are there in a given area?”.
In this localization system, the world is considered a square region, composed of cells. Each cell has a coordinate , . Coordinates are 1-indexed. For a square, we have , (see the figure).

Please help Mokia write a program to compute how many users are in a rectangular region.
Input Format
There are three types of commands with the following meanings:
| Command | Parameters | Meaning |
|---|---|---|
| Initialize an all-zero matrix. This command appears exactly once at the beginning. | ||
| Add users to cell . is a positive integer. | ||
| Query the number of users in the rectangle defined by , . | ||
| none | End the program. This command appears exactly once at the end. |
The input consists of multiple lines. Each line contains several integers representing one command.
Output Format
For every command , output one integer on a separate line: the number of users currently in the queried rectangle.
0 4
1 2 3 3
2 1 1 3 3
1 2 2 2
2 2 2 3 4
3
3
5
Hint
Constraints
For of the testdata, it is guaranteed that:
- .
- , , , .
- The number of command does not exceed .
- The number of command does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号