Let A[1...n]
be an array consisting of n different numbers.
The pair (i, j)
is called an inverse, If i < j and A [i] > A [j]
.
Example:
A := (2, 3, 8, 6, 1) => A has 5 inverses.
Task:
Write program to find the number of inverses of the array A [1..n] such that the complexity of the algorithm is O (n * logn).