#P3801. 红色的幻想乡

    ID: 2741 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>线段树树状数组洛谷原创容斥

红色的幻想乡

Description

After the last failure, Remilia decided to launch the Scarlet Mist incident again. To avoid being exorcised by Reimu, she decided to release the red mist in a strange formation.

We model Gensokyo as an n×mn \times m grid. Initially, no cell is covered by red mist. Each time, Remilia stands on some cell and emits one infinitely long red mist in each of the four cardinal directions, affecting the entire row/column, but not the cell she stands on. If two red mists collide, they settle and disappear due to excessive density. Reimu notices this incident and decides to resolve it. Before that, she wants to know the density of red mist in a rectangular region, which can be summarized as two operations:

1 x y Remilia stands at coordinate (x,y)(x, y) and releases infinitely long red mist in the four directions.

2 x1 y1 x2 y2 Query the number of cells covered by red mist within the rectangle with top-left (x1,y1)(x_1, y_1) and bottom-right (x2,y2)(x_2, y_2).

Input Format

The first line contains three integers n,m,qn, m, q, meaning the size of Gensokyo is n×mn \times m, and there are qq operations.

Then follow qq lines. Each line contains 33 or 55 integers separated by spaces, as described above.

Output Format

For each operation of type 22, output one line with one integer representing the answer to that query.

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

8

Hint

Sample Input/Output 1 Explanation

Let o denote no red mist, and x denote red mist. After two releases of red mist, the map of Gensokyo looks like:

oxox
xoxo
oxox
xoxo

Constraints

  • For 20%20\% of the testdata, 1n,m,q2001 \le n, m, q \le 200.
  • For 40%40\% of the testdata, 1n,m,q1031 \le n, m, q \le 10^3.
  • For 100%100\% of the testdata, 1n,m,q1051 \le n, m, q \le 10^5, 1x1,x2,xn1 \le x_1, x_2, x \le n, x1x2x_1 \le x_2, 1y1,y2,ym1 \le y_1, y_2, y \le m, y1y2y_1 \le y_2.

Translated by ChatGPT 5