#P4024. [CTSC2012] 统计学家

[CTSC2012] 统计学家

Description

Given an N×MN \times M integer matrix {A[i,j]}\{A[i,j]\} (1iN1 \le i \le N, 1jM1 \le j \le M). You need to answer KK queries. The ii‑th query asks you to count the number of 2D inversion pairs (x1,y1,x2,y2)(x_1, y_1, x_2, y_2) that satisfy all of the following:

  • ui,1x1x2ui,2u_{i,1} \le x_1 \le x_2 \le u_{i,2},
  • vi,1y1y2vi,2v_{i,1} \le y_1 \le y_2 \le v_{i,2},
  • A[x1,y1]>A[x2,y2]A[x_1, y_1] > A[x_2, y_2].

Input Format

This is an answer-submission problem. The input files are named rev1.in ~ rev10.in.

For each rev*.in, the first line contains three positive integers N,M,KN, M, K.

The next NN lines each contain MM integers, giving the matrix AA, where the jj‑th number in the ii‑th line is A[i,j]A[i, j]. Then the next KK lines each contain four integers describing the queries; in the ii‑th of these lines, the four integers are ui,1,vi,1,ui,2,vi,2u_{i,1}, v_{i,1}, u_{i,2}, v_{i,2}.

Output Format

On Luogu, output a single integer: the XOR of all KK answers (i.e., the XOR of the answers to all queries).

Note: The sample is only for understanding the problem and is not the final output format.

(Original answer-submission format for each rev*.out: it contains KK lines, where the ii‑th line is the answer to the ii‑th query, i.e., the number of 2D inversion pairs that satisfy the corresponding conditions.)

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

0
4
19

Hint

Please keep the input files *.in and your outputs *.out safe and back them up in time to avoid accidental deletion.

Translated by ChatGPT 5