该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Recall the problem of finding the number of inversions. As in the course, we are given a sequence of numbers , and we define an inversion to be a pair such that .
We motivated the problem of counting inversions as a good measure of how different two orderings are. However, one might feel that this measure is too sensitive. Let's call a pair a significant inversion if and . Give an algorithm to count the number of significant inversions between two orderings.
The array contains N elements (). All elements are in the range from to .
The first line contains one integer N, indicating the size of the array. The second line contains N elements in the array.
Output a single integer which is the number of pairs of significant inversions.