#P4148. Grid Sum Query and Update

    ID: 17396 Type: Default 1000ms 256MiB

Grid Sum Query and Update

Grid Sum Query and Update

You are given an N×NN \times N chessboard with all cells initially set to 00. You need to perform the following operations:

  1. 1 x y A: Increase the value in cell (x,y)(x,y) by AA, where 1x,yN1\le x,y\le N and AA is a positive integer.
  2. 2 x_1 y_1 x_2 y_2: Query the sum of the values in the rectangular region with the top-left cell (x1,y1)(x_1,y_1) and the bottom-right cell (x2,y2)(x_2,y_2), where 1x1x2N1\le x_1\le x_2\le N and 1y1y2N1\le y_1\le y_2\le N.
  3. 3: Terminate the program.

inputFormat

The first line of input contains a single integer NN, the size of the chessboard. Each subsequent line contains an operation in one of the following formats:

1 x y A
2 x1 y1 x2 y2
3 (this operation indicates the termination of the input).

Read operations until a line with operation type 3 is encountered.

outputFormat

For each query operation (operation type 2), output the sum of the values in the specified rectangular region on its own line.

sample

3
1 1 1 5
1 2 2 3
2 1 1 2 2
3
8

</p>