#P4054. Grid Weight Queries

    ID: 17302 Type: Default 1000ms 256MiB

Grid Weight Queries

Grid Weight Queries

You are given a grid of size \(n \times m\) with an integer weight in each cell. You need to process \(q\) operations on this grid. There are two types of operations:

  • Update Operation: Change the weight of a specific cell.
  • Query Operation: Count the number of occurrences of a specific weight within a submatrix.

Each operation is provided in one of the following formats:

  • Update: 1 x y val - update the cell at row \(x\) and column \(y\) (1-indexed) to the new weight \(val\).
  • Query: 2 x1 y1 x2 y2 k - count the occurrences of the weight \(k\) in the submatrix with top-left cell \((x1, y1)\) and bottom-right cell \((x2, y2)\) (all 1-indexed).

Output the result of each query operation in the order they appear.

inputFormat

The first line contains three integers \(n\), \(m\), and \(q\) — the number of rows, columns, and operations respectively.

The next \(n\) lines each contain \(m\) integers representing the initial weights of the grid's cells.

The following \(q\) lines each describe an operation in one of the two formats mentioned above.

outputFormat

For each query operation (operations starting with 2), output a single integer — the count of cells in the specified submatrix whose weight is equal to \(k\).

sample

3 3 5
1 2 3
4 5 6
7 8 9
2 1 1 3 3 5
1 2 2 5
2 1 1 3 3 5
2 2 2 3 3 9
2 1 1 1 2 2
1

1 1 1

</p>