#K6826. Matrix Processor

    ID: 32825 Type: Default 1000ms 256MiB

Matrix Processor

Matrix Processor

You are given a 2D matrix of integers with dimensions \(n \times m\). The matrix uses 1-indexed notation. You need to perform a series of operations on the matrix. There are two types of operations:

  • Q x1 y1 x2 y2: Query the sum of all elements in the submatrix from \( (x_1, y_1) \) to \( (x_2, y_2) \) (inclusive). The sum is given by \[ \sum_{i=x_1}^{x_2} \sum_{j=y_1}^{y_2} A_{i,j} \]</p>
  • U x y v: Update the element at position \( (x, y) \) to \(v\).

For each query operation, output the result on a new line. Update operations do not produce any output.

inputFormat

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

  1. The first line contains two integers \(n\) and \(m\), representing the number of rows and columns of the matrix.
  2. The next \(n\) lines each contain \(m\) integers representing the initial matrix.
  3. The next line contains an integer \(q\), the number of operations to perform.
  4. Each of the next \(q\) lines describes an operation in one of the following forms:
    • Q x1 y1 x2 y2 for a query operation.
    • U x y v for an update operation.

outputFormat

For every query operation (lines starting with 'Q'), output the sum of the specified submatrix on a separate line to standard output (stdout).

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

50 33

</p>