QOJ.ac

QOJ

Points totaux : 100 Sortie uniquement

#10791. The Statistician

Statistiques

Given an $N \times M$ integer matrix $\{A[i, j]\}$ ($1 \le i \le N, 1 \le j \le M$), answer $K$ queries. The $i$-th query asks to count the number of 2D inversions $(x_1, y_1, x_2, y_2)$ that satisfy the following conditions:

$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

The first line contains three positive integers $N$, $M$, and $K$. The next $N$ lines each contain $M$ integers representing the matrix $A$, where the $j$-th number in the $i$-th line is $A[i, j]$. The following $K$ lines each contain four integers representing the queries, where the $i$-th line contains $u_{i,1}$, $v_{i,1}$, $u_{i,2}$, and $v_{i,2}$.

Output

The output should contain $K$ lines. The $i$-th line should contain a single integer, which is the answer to the $i$-th query, representing the number of 2D inversions satisfying the corresponding conditions.

Examples

Input 1

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

Output 1

0
4
19

ou importez des fichiers un par un

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.