#C7600. Wildlife Photography Grid Operations

    ID: 51490 Type: Default 1000ms 256MiB

Wildlife Photography Grid Operations

Wildlife Photography Grid Operations

Problem Statement: You are given a grid with ( R ) rows and ( C ) columns representing a wildlife photography board. Each cell in the grid may contain a photograph (indicated by a non-zero photo ID) or be empty (represented by 0). You need to execute ( Q ) operations on this grid. The operations are given in the following formats:

  • 1 x y photo_id: Place a photograph with the specified photo ID at position \( (x, y) \).
  • 2 x y: Remove the photograph at position \( (x, y) \).
  • 3 x1 y1 x2 y2: Count the number of photographs in the sub-grid defined by the top-left cell \( (x1, y1) \) and the bottom-right cell \( (x2, y2) \) (inclusive).

For each query of type 3, output the count of non-empty cells within the specified sub-grid. Note that positions are 1-indexed.

inputFormat

The first line contains three space-separated integers ( R ), ( C ), and ( Q ). Each of the following ( Q ) lines contains an operation in one of the formats described above. All input is given via standard input (stdin).

outputFormat

For every query operation (operation type 3), output a single integer on a new line representing the number of photographs in the specified sub-grid. The output should be printed to standard output (stdout).## sample

5 5 4
1 2 3 1
1 4 5 2
3 1 1 5 5
2 2 3
2