a1, a2, ..., an
sequence numbers are given. Now, give an algorithm with O(nlg n)
running time to calculate the number of pairs (i, j)
for i < j
and ai > aj
.
Input: The number of test cases has came in first. For each test case number has came n
number for first and then a1, a2, ..., an
in the next line. N <= 100000
ai <= 100000000
Now, I want the output as follows:
Output: For each test is printed only one number (that is the asked value in the beginning of the question).
Sample Input:
2
4
3 2 1 5
5
8 9 3 2 1
Sample Output:
3
9