#P14192. [ICPC 2024 Hangzhou R] Fuzzy Ranking
[ICPC 2024 Hangzhou R] Fuzzy Ranking
题目描述
In Pigeland, there are universities, numbered from to . Each year, several ranking organizations publish rankings of these universities. This year, there are ranking lists, where each list is a permutation of integers from to , representing the universities. In each ranking, the closer a university is to the beginning of the permutation, the better its ranking is in this list.
:::align{center}

A true story in the 2024 ICPC World Final. :::
Supigar, a year-4 student who wants to apply for PhD programs in Pigeland, has his own method to evaluate the universities comprehensively. He considers that university is to another university if and only if:
- is ranked better than in at least one list, or
- is ranked better than in at least one list, and is superior to .
Clearly, under this definition, there might exist some pairs of universities and () such that is superior to while is also superior to . Supigar calls such pairs .
Supigar has queries, where the -th query can be represented by three integers , and (). For each query, he will consider the -th rank list and all the universities between the -th position and the -th position (both inclusive) in that list. He wants to know, among these universities, how many pairs of them are fuzzy. Note that the definition of fuzzy pairs requires considering the superior relationships among all rank lists.
输入格式
There are multiple test cases. The first line of the input contains an integer () indicating the number of test cases. For each test case:
The first line contains three integers , , and (, ) indicating the number of universities, rank lists, and queries, respectively.
For the following lines, the -th line contains distinct integers () indicating the -th rank list.
For the following lines, the -th line contains three integers , , and (, ) indicating the index of the rank list and the query range for the -th query.
- The real value of is equal to .
- The real value of is equal to .
- The real value of is equal to .
Where is the answer for the -th query. Specifically, we define . With the encoded queries, you're forced to calculate the answer to each query before processing the next one. It's guaranteed that and after decoding.
It is also guaranteed that neither the sum of nor the sum of of all test cases will exceed .
输出格式
For each test case output lines. Each line contains a single integer representing the number of fuzzy pairs as the answer to the -th query.
2
5 2 2
1 2 3 4 5
5 4 3 2 1
1 0 2
1 2 1
5 3 3
1 2 3 4 5
1 3 2 4 5
1 2 3 5 4
0 0 2
0 2 3
1 0 3
3
10
1
1
2
提示
For the first sample test case, the two decoded queries are and .
For the second sample test case, the three decoded queries are , , and .