#K56122. Grid Manipulation and Query

    ID: 30129 Type: Default 1000ms 256MiB

Grid Manipulation and Query

Grid Manipulation and Query

You are given a 2D grid with \(n\) rows and \(m\) columns, initially filled with zeros. You need to process a sequence of \(k\) commands that modify the grid. Each command will be in one of the two formats:

  • RowAdd r x: Add the integer \(x\) to every element in row \(r\).
  • ColAdd c x: Add the integer \(x\) to every element in column \(c\).

After processing the commands, you are given \(q\) queries. Each query provides a pair of integers \( (u, v) \) representing the row and column indices. For each query, output the value at the cell in row \(u\) and column \(v\).

Note: All indices are 1-indexed.

inputFormat

The input is given in the following format from stdin:

n m k
command_1
command_2
... (k commands)
q
u1 v1
u2 v2
... (q queries)

Here:

  • \(n, m\) are the numbers of rows and columns respectively.
  • \(k\) is the number of commands.
  • Each command is either in the format RowAdd r x or ColAdd c x.
  • \(q\) is the number of queries.
  • Each query consists of two integers \(u\) and \(v\), the cell coordinates.

outputFormat

For each query, print the value in the specified cell on a new line to stdout.

## sample
3 3 3
RowAdd 1 5
ColAdd 3 4
RowAdd 2 3
2
1 1
2 3
5

7

</p>