#P4024. Counting 2D Inversion Pairs in a Submatrix
Counting 2D Inversion Pairs in a Submatrix
Counting 2D Inversion Pairs in a Submatrix
Given an integer matrix (, ), answer queries. For the -th query, count the number of 2D inversion pairs satisfying the conditions:
Note that the indices of the matrix are 1-indexed.
inputFormat
The first line contains three integers , , and , representing the number of rows, the number of columns of the matrix, and the number of queries, respectively.
The next lines each contain integers, where the -th integer on the -th line represents .
Each of the following lines contains four integers , , , and , describing a query that asks for the number of inversion pairs in the submatrix with rows from to and columns from to .
outputFormat
For each query, print one line containing a single integer representing the number of inversion pairs in the specified submatrix.
sample
3 3 2
1 2 3
4 5 6
7 8 9
1 2 1 2
2 3 2 3
0
0
</p>