#K95097. Grid Operations
Grid Operations
Grid Operations
You are given a grid of size \(R \times C\), with all cells initially set to 0. Your task is to perform a sequence of operations on the grid. There are two types of operations:
- I r0 c0 r1 c1 x: Increment all cells in the subgrid with top-left coordinate \((r_0, c_0)\) and bottom-right coordinate \((r_1, c_1)\) (inclusive) by an integer \(x\).
- Q r c: Query the current value at the cell \((r, c)\).
Process the operations in the order given and output the result of each query operation.
inputFormat
The input is read from standard input (stdin) in the following format:
Line 1: Two integers (R) and (C) representing the number of rows and columns of the grid. Line 2: An integer (Q) representing the total number of operations. Next (Q) lines: Each line contains an operation in one of the following formats:
- For an increment operation: "I r0 c0 r1 c1 x" where (0 \leq r0 \leq r1 < R), (0 \leq c0 \leq c1 < C), and (x) is the integer to add.
- For a query: "Q r c" where (0 \leq r < R) and (0 \leq c < C).
Note: Coordinates are zero-indexed.
outputFormat
For each query operation (lines beginning with "Q"), output the value of the specified cell on a separate line to standard output (stdout).## sample
4 5
6
I 1 1 2 2 3
I 0 0 1 1 2
Q 1 1
Q 2 2
I 0 0 3 4 1
Q 3 4
5
3
1
</p>