#P11015. Inversion Pair
Inversion Pair
Background
.
Problem Description
For a sequence , we define as the number of inversion pairs in .
Note: An inversion pair here means a pair that satisfies and .
Now you are given a sequence , which is a permutation of the integers . That is, for any , we have , all are integers, and they are all distinct.
There is a graph with nodes, numbered . For any two nodes with indices , we add an undirected edge between them with weight .
There are queries. Each query gives two nodes numbered , and you need to find the shortest path between them.
Input Format
The first line contains two integers .
The second line contains integers representing the sequence .
The next lines each contain two integers, representing one query .
Output Format
For each query:
Output one integer, the length of the required shortest path.
3 2
3 1 2
1 3
2 2
1
0
Hint
For all testdata, it is guaranteed that: , , .
| Score | Special Property | |||
|---|---|---|---|---|
| None | ||||
Translated by ChatGPT 5