#C1708. Grid Transformation with Rectangle Operations

    ID: 44943 Type: Default 1000ms 256MiB

Grid Transformation with Rectangle Operations

Grid Transformation with Rectangle Operations

Given a grid of dimensions \(R \times C\), you are provided with \(Q\) operations. Each operation is specified by five integers: \(r_1\), \(c_1\), \(r_2\), \(c_2\), and \(val\). For each operation, add the integer \(val\) to every cell in the sub-grid defined by the top-left coordinate \((r_1, c_1)\) and the bottom-right coordinate \((r_2, c_2)\). The grid is 0-indexed.

The transformation is defined by the formula:

\( grid[i][j] = initial\_grid[i][j] + \sum_{k \; \text{s.t.} \; r_{1_k} \le i \le r_{2_k} \; \text{and} \; c_{1_k} \le j \le c_{2_k}} val_k \)

Your task is to output the transformed grid after applying all the operations.

inputFormat

The input is read from stdin as follows:

  • The first line contains two integers \(R\) and \(C\) -- the number of rows and columns of the grid.
  • The next \(R\) lines each contain \(C\) integers representing the grid.
  • The following line contains a single integer \(Q\), the number of operations.
  • Each of the next \(Q\) lines contains five integers: \(r_1\), \(c_1\), \(r_2\), \(c_2\), and \(val\), describing an operation.

outputFormat

The output should be printed to stdout. Print the transformed grid after performing all operations. Output (R) lines, and each line should contain (C) space-separated integers representing a row of the grid.## sample

3 4
1 2 3 4
5 6 7 8
9 10 11 12
1
0 0 1 1 5
6 7 3 4

10 11 7 8 9 10 11 12

</p>