#C10813. Grid Operations on a 2D Array

    ID: 40060 Type: Default 1000ms 256MiB

Grid Operations on a 2D Array

Grid Operations on a 2D Array

You are given a two-dimensional grid with N rows and M columns. Initially, all cells are set to 0. You will be provided with K operations to perform on the grid. There are two types of operations:

  • Update Operation: "1 x y val" sets the cell located at row x and column y to the value val.
  • Query Operation: "2 x1 y1 x2 y2" computes the sum of the cells in the subgrid with top-left corner (x1,y1) and bottom-right corner (x2,y2).

For a given query operation, output the computed sum. All indices given in the operations are 1-indexed.

Mathematical Description:

Let \(A\) be an \(N \times M\) grid initialized as \(A_{i,j} = 0\) for \(1 \leq i \leq N, 1 \leq j \leq M\). For an update operation, set \(A_{x,y} = val\). For a query operation, calculate:

\[ S = \sum_{i=x_1}^{x_2}\sum_{j=y_1}^{y_2} A_{i,j} \]

inputFormat

The first line contains three space-separated integers: N (number of rows), M (number of columns) and K (number of operations).

The next K lines each contain an operation in one of the following formats:

  • For an update operation: 1 x y val
  • For a query operation: 2 x1 y1 x2 y2

outputFormat

For each query operation, output the computed sum on a new line. If there are no query operations, the program should not output anything.

## sample
3 3 5
1 1 1 5
1 2 2 7
2 1 1 2 2
1 3 3 3
2 1 1 3 3
12

15

</p>