#P4054. [JSOI2009] 计数问题

    ID: 3008 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2009各省省选树状数组江苏前缀和概率论,统计

[JSOI2009] 计数问题

Description

There is an n×mn \times m grid. Initially, each cell has an integer weight. Then there are 2 types of operations:

  • Change the weight of a cell.
  • Query how many times a specified weight appears in a submatrix.

Input Format

The first line contains two integers n,mn, m.

Then follow nn lines, each with mm integers. In the (i+1)(i+1)-th line, the jj-th number is the initial weight of cell (i,j)(i, j).

Then an integer QQ is given.

Then there are QQ lines, each describing an operation.

Operation 1: A line with four integers 1 x y c1\ x\ y\ c, meaning set the weight of cell (x,y)(x, y) to cc.

Operation 2: A line with six integers 2 x1 x2 y1 y2 c2\ x_1\ x_2\ y_1\ y_2\ c, meaning query the number of cells whose weight is cc and satisfy x1xx2,y1yy2x_1\le x\le x_2, y_1\le y\le y_2.

Output Format

For each operation 2, output one integer per line in the order they appear, representing the required count.

3 3
1 2 3
3 2 1
2 1 3
3
2 1 2 1 2 1
1 2 3 2
2 2 3 2 3 2
1
2

Hint

Constraints

For 30%30\% of the testdata: n,m30n, m\le 30, Q5×104Q\le 5\times 10^4.

For 100%100\% of the testdata: 1n,m3001\le n, m\le 300, 1Q2×1051\le Q\le 2\times 10^5.

For operation 1, it is guaranteed that 1xn1\le x\le n, 1ym1\le y\le m, 1c1001\le c\le 100.

For operation 2, it is guaranteed that 1x1x2n1\le x_1\le x_2\le n, 1y1y2m1\le y_1\le y_2\le m, 1c1001\le c\le 100.

Translated by ChatGPT 5