#C3135. Farm Grid Operations

    ID: 46529 Type: Default 1000ms 256MiB

Farm Grid Operations

Farm Grid Operations

You are given a 2D grid representing a farm. Initially, every cell in the grid is empty (denoted by 0). You must process q operations on this grid. The grid uses 1-indexed coordinates. There are three types of operations:

  • 1 i j: Plant a crop at cell \\(i, j\\). This sets the value at the cell to 1 if it is currently 0.
  • 2 i j: Remove the crop from cell \\(i, j\\). This sets the value at the cell to 0 if it is currently 1.
  • 3 x1 y1 x2 y2: Query the number of crops in the subrectangle defined by the top-left cell \\(x_{1}, y_{1}\\) and the bottom-right cell \\(x_{2}, y_{2}\\). In other words, count the number of 1's in the rectangle.

Your task is to execute the operations in order and output the result of each query (operation type 3) on a new line.

The query rectangle is defined by the formula: \\[ \text{Query Rectangle} = \{(i,j) \mid x_{1} \le i \le x_{2},\; y_{1} \le j \le y_{2}\} \\]

inputFormat

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

Each of the following \(q\) lines contains one operation in one of the following formats:

  • 1 i j — Plant a crop at cell \(i,j\).
  • 2 i j — Remove a crop from cell \(i,j\).
  • 3 x1 y1 x2 y2 — Query the total number of crops in the rectangle defined by the top-left cell \( (x_{1}, y_{1}) \) and the bottom-right cell \( (x_{2}, y_{2}) \).

outputFormat

For each query operation (type 3), print the result — the count of crops in the specified subrectangle — on a new line. If there are no query operations, no output is produced.

## sample
5 4 7
1 1 1
1 2 2
1 3 3
3 1 1 3 3
2 2 2
3 1 1 3 3
3 1 1 5 4
3

2 2

</p>