#K38497. Grid Manager

    ID: 26211 Type: Default 1000ms 256MiB

Grid Manager

Grid Manager

You are given an m × m grid initially filled with zeros. You are required to process a series of n operations on this grid. The operations include:

  • place x y k: Add k people to the cell at position (x, y).
  • evacuate x y k: Remove k people from the cell at position (x, y).
  • count x1 y1 x2 y2: Count the total number of people in the sub-grid whose top-left corner is (x1, y1) and bottom-right corner is (x2, y2).

Formally, if we denote the grid as A, the operation count computes the sum \[ S = \sum_{i=x_1}^{x_2} \sum_{j=y_1}^{y_2} A_{ij} \] and outputs S.

Your task is to process all requests in order and output the result for every count operation.

inputFormat

The first line contains two integers m and n where m is the size of the grid and n is the number of operations.

The following n lines each contain one operation in one of the following formats:

  • place x y k
  • evacuate x y k
  • count x1 y1 x2 y2

Note: 0-based indexing is used for the cells.

outputFormat

For each count operation, output the result (an integer) on a new line in the order they appear in the input.

## sample
5 8
place 0 0 10
place 1 1 20
place 2 2 15
count 0 0 2 2
evacuate 1 1 5
count 0 0 2 2
place 3 3 5
count 2 2 4 4
45

40 20

</p>