#K12926. Grid Update and Query Operations

    ID: 23799 Type: Default 1000ms 256MiB

Grid Update and Query Operations

Grid Update and Query Operations

You are given a 2D grid with n rows and m columns. Your task is to process Q operations. There are two types of operations:

  • Update Operation: Given in the form 1 x y v, update the value at cell \( (x, y) \) to \( v \). Note that the indices are 1-based.
  • Query Operation: Given in the form 2 x_1 y_1 x_2 y_2, output the sum of all values in the subgrid defined by the top-left cell \( (x_1, y_1) \) and the bottom-right cell \( (x_2, y_2) \). The formula for the query is given by \[ S = \sum_{i=x_1}^{x_2}\sum_{j=y_1}^{y_2}{a_{ij}}, \] where \( a_{ij} \) denotes the value in the cell at row \( i \) and column \( j \).

You should implement the grid such that it can handle the operations and output the results for all query operations.

inputFormat

The input is read from standard input (stdin) and has the following format:

 n m Q
 a11 a12 ... a1m
 a21 a22 ... a2m
 ...
 an1 an2 ... anm
 operation1
 operation2
 ...
 operationQ

Here, n and m are the dimensions of the grid. Each of the next n lines contains m integers representing the grid values. Then Q operations are provided. Each operation is either an update operation of the form 1 x y v or a query operation of the form 2 x1 y1 x2 y2.

outputFormat

For each query operation (operations starting with 2), output the sum of the specified subgrid on a new line to standard output (stdout).

## sample
3 3 1
1 2 3
4 5 6
7 8 9
2 1 1 3 3
45

</p>