#C3269. Building Simulation

    ID: 46677 Type: Default 1000ms 256MiB

Building Simulation

Building Simulation

In this problem, you are given a 2D grid representing a building with n rows and m columns. Initially, every cell in the grid has a height of 0. You need to process k operations to simulate building construction and deconstruction. The operations are defined as follows:

  1. (\texttt{add x y z h}): Increase the height at cell ((x, y)) by (h). Note that the parameter (z) is provided in the command but is not used for the simulation.

  2. (\texttt{remove x y z h}): Decrease the height at cell ((x, y)) by (h), but the height cannot drop below 0.

  3. (\texttt{height x y}): Output the current height at cell ((x, y)).

  4. (\texttt{total_height}): Output the total sum of heights of all cells in the building.

Process the commands sequentially, and for every command of type (\texttt{height}) and (\texttt{total_height}), output the result on a new line. The input is read from standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line of input contains three integers (n), (m), and (k) representing the number of rows, the number of columns, and the number of commands respectively. Each of the following (k) lines contains one command in one of the following formats:

  • For addition and removal operations: (\texttt{command x y z h}).
  • For querying the height of a cell: (\texttt{height x y}).
  • For querying the total height: (\texttt{total_height}).

outputFormat

For each (\texttt{height}) and (\texttt{total_height}) command in the input, output the result on a separate line to standard output (stdout).## sample

3 3 5
add 1 1 1 5
add 2 2 2 3
height 1 1
remove 1 1 1 2
total_height
5

6

</p>