#C5001. Grid Operations on an N×N Matrix

    ID: 48603 Type: Default 1000ms 256MiB

Grid Operations on an N×N Matrix

Grid Operations on an N×N Matrix

You are given an integer N representing the size of a grid, and a series of operations to perform on this grid. Initially, the grid is filled with zeros. The grid is of size \( N \times N \).

There are two types of operations provided in the input:

  • SET x y val: Update the cell at row x and column y with the integer val.
  • SUM x1 y1 x2 y2: Compute the sum of all cells in the rectangular sub-grid with top-left corner (\(x_1, y_1\)) and bottom-right corner (\(x_2, y_2\)) inclusive.

Output the result for each "SUM" operation in the order in which they appear.

inputFormat

The input is given through standard input (stdin) in the following format:

N Q
operation_1
operation_2
...
operation_Q

Where:

  • N is the size of the grid.
  • Q is the number of operations.
  • Each operation is either in the form SET x y val or SUM x1 y1 x2 y2.

All indices are assumed to be 0-indexed.

outputFormat

For each SUM operation, output the computed sum on a new line to standard output (stdout).

## sample
4 5
SET 1 1 5
SET 2 2 7
SUM 0 0 3 3
SUM 1 1 2 2
SET 3 3 4
12

12

</p>