#T535. 求逆序对

求逆序对

Description

Given a sequence a1,a2,,ana_1, a_2, \dots, 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. The task is to count the total number of inversions in the sequence.

Input Format

The first line contains nn, the length of the sequence. The following nn lines contain the elements of the sequence, where the (i+1)(i+1)-th line represents the ii-th element of the sequence.

Output Format

The total number of inversions in the sequence.

4
3
2
3
2
3

译文

CodesOnline