#C5922. Grid Operations
Grid Operations
Grid Operations
You are given a (N \times M) grid (with rows numbered from 1 to (N) and columns from 1 to (M)), initially filled with zeros. You need to process (Q) operations sequentially. The operations are one of the following three types:
- row i x: Add the integer \(x\) to every cell in the \(i\)-th row.
- col j x: Add the integer \(x\) to every cell in the \(j\)-th column.
- max: Query and output the current maximum value present in the grid.
max
command is encountered, print the maximum value in the grid at that moment.
inputFormat
The input is given via standard input in the following format:
- The first line contains three integers \(N\), \(M\), and \(Q\) separated by spaces — representing the number of rows, the number of columns, and the number of operations respectively.
- The next \(Q\) lines describe an operation. Each operation is in one of the following formats:
row i x
— add the integer \(x\) to each cell of the \(i\)-th row.col j x
— add the integer \(x\) to each cell of the \(j\)-th column.max
— output the current maximum value in the grid.
outputFormat
For each max
operation in the input, output a single line to standard output containing the maximum value in the grid after applying all preceding operations.## sample
2 3 5
row 1 4
col 2 2
max
row 2 3
max
6
6
</p>