#C852. Process Bookshelf Labels

    ID: 52511 Type: Default 1000ms 256MiB

Process Bookshelf Labels

Process Bookshelf Labels

You are given T test cases. In each test case, you have a bookshelf configuration defined by two numbers \(S\) and \(C\):

  • \(S\) is the number of shelves.
  • \(C\) is the number of slots (or columns) in each shelf.

You are also provided with a list of \(S \times C\) integers representing the labels on the books in each slot (given in row-major order). Then, you are given an integer \(O\) representing the number of operations. Each operation is described by three integers \(A\), \(B\), and \(K\) (all 1-indexed), meaning that for shelf \(K\), you should increment by 1 the labels in slots from position \(A\) to \(B\) (inclusive).

After performing all the operations, compute the sum of the labels on each shelf. For each test case, output a single line containing \(S\) integers where the \(i\)th integer is the sum of labels on the \(i\)th shelf.

Note: The indices in the operations are 1-indexed whereas typical programming languages use 0-indexed arrays. Make sure to convert these indices appropriately.

inputFormat

The input is read from stdin and has the following format:

T
S C
label[1] label[2] ... label[S*C]
O
A1 B1 K1
A2 B2 K2
... (O lines)
... (repeat the above block for each test case)

Where:

  • T: The number of test cases.
  • S: The number of shelves.
  • C: The number of slots per shelf.
  • Next line contains \(S \times C\) integers representing the labels placed on the shelves in row-major order.
  • O: The number of operations.
  • Each operation consists of three space-separated integers \(A\), \(B\), and \(K\) (1-indexed) as described above.

outputFormat

For each test case, output a single line to stdout containing \(S\) space-separated integers. Each integer is the sum of the labels on the corresponding shelf after all operations have been applied.

## sample
1
2 5
1 2 3 4 5 6 7 8 9 10
3
1 3 1
2 5 2
1 2 1
20 44

</p>