#K47027. Grid Operations

    ID: 28107 Type: Default 1000ms 256MiB

Grid Operations

Grid Operations

You are given a grid of integers with (n) rows and (m) columns. You need to process (t) operations on this grid. There are three types of operations:

  1. Row Update: R r v – Set all elements in row (r) to the value (v).
  2. Column Update: C c v – Set all elements in column (c) to the value (v).
  3. Query: Q r_1 c_1 r_2 c_2 – Compute the sum of all elements in the submatrix defined by the top-left coordinate ((r_1, c_1)) and bottom-right coordinate ((r_2, c_2)) (both inclusive).

Note: The grid indices are 1-indexed.

inputFormat

The first line contains two integers (n) and (m), denoting the number of rows and columns respectively. The next (n) lines each contain (m) integers representing the grid. The following line contains an integer (t), representing the number of operations. Each of the next (t) lines contains an operation in one of the following formats:

• R r v • C c v • Q r1 c1 r2 c2

outputFormat

For each query operation (lines starting with the character 'Q'), output the result on a separate line.## sample

4 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
4
R 2 5
C 3 7
Q 2 2 3 4
Q 1 1 4 5
50

184

</p>