#T738. 求逆序对

求逆序对

Description

Given a sequence a1,a2,,ana_1, a_2, \ldots, a_n, if there exists a pair (i,j)(i, j) such that i<ji < j and ai>aja_i > a_j, then it is called an inversion pair. The task is to count the total number of inversion pairs.

Input Format

The first line contains nn, representing the length of the sequence. The next nn lines each contain one element of the sequence, where the (i+1)(i+1)-th line corresponds to the ii-th element of the sequence.

Output Format

The total number of inversion pairs.

4
3
2
3
2
3

Source

CodesOnline