P4024 [CTSC2012] Statistician

Background

[Input files](https://pan.baidu.com/s/1i5laUcH). Due to the limitation of the Luogu judge, please output the XOR of all answers at the end. Scoring: For each test point, if you produce an output and it exactly matches the official output, you get 10 points; otherwise, you get 0 points.

Description

Given an $N \times M$ integer matrix $\{A[i,j]\}$ ($1 \le i \le N$, $1 \le j \le M$). You need to answer $K$ queries. The $i$‑th query asks you to count the number of 2D inversion pairs $(x_1, y_1, x_2, y_2)$ that satisfy all of the following: - $u_{i,1} \le x_1 \le x_2 \le u_{i,2}$, - $v_{i,1} \le y_1 \le y_2 \le v_{i,2}$, - $A[x_1, y_1] > A[x_2, y_2]$.

Input Format

This is an answer-submission problem. The [input files](https://pan.baidu.com/s/1i5laUcH) are named `rev1.in ~ rev10.in`. For each `rev*.in`, the first line contains three positive integers $N, M, K$. The next $N$ lines each contain $M$ integers, giving the matrix $A$, where the $j$‑th number in the $i$‑th line is $A[i, j]$. Then the next $K$ lines each contain four integers describing the queries; in the $i$‑th of these lines, the four integers are $u_{i,1}, v_{i,1}, u_{i,2}, v_{i,2}$.

Output Format

On Luogu, output a single integer: the XOR of all $K$ 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 $K$ lines, where the $i$‑th line is the answer to the $i$‑th query, i.e., the number of 2D inversion pairs that satisfy the corresponding conditions.)

Explanation/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