#P4148. Grid Sum Query and Update
Grid Sum Query and Update
Grid Sum Query and Update
You are given an chessboard with all cells initially set to . You need to perform the following operations:
1 x y A
: Increase the value in cell by , where and is a positive integer.2 x_1 y_1 x_2 y_2
: Query the sum of the values in the rectangular region with the top-left cell and the bottom-right cell , where and .3
: Terminate the program.
inputFormat
The first line of input contains a single integer , 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>