#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 w×ww\times w square region, composed of 1×11\times 1 cells. Each cell has a coordinate (x,y)(x, y), 1x,yw1\leq x,y\leq w. Coordinates are 1-indexed. For a 4×44\times 4 square, we have 1x41\leq x\leq 4, 1y41\leq y\leq 4 (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
00 ww Initialize an all-zero matrix. This command appears exactly once at the beginning.
11 x y ax\ y\ a Add aa users to cell (x,y)(x, y). aa is a positive integer.
22 x1 y1 x2 y2x_1\ y_1\ x_2\ y_2 Query the number of users in the rectangle defined by x1xx2x_1\leq x\leq x_2, y1yy2y_1\leq y\leq y_2.
33 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 22, 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 100%100\% of the testdata, it is guaranteed that:

  • 1w2×1061\leq w\leq 2\times 10 ^ 6.
  • 1x1x2w1\leq x_1\leq x_2\leq w, 1y1y2w1\leq y_1\leq y_2\leq w, 1x,yw1\leq x,y\leq w, 0<a100000<a\leq 10000.
  • The number of command 11 does not exceed 160000160000.
  • The number of command 22 does not exceed 1000010000.

Translated by ChatGPT 5