#P1908. 逆序对
逆序对
Description
Cat TOM and mouse JERRY are competing again. But since they are adults now, they no longer enjoy playing chase games; these days, they like counting.
Recently, old cat TOM read about something humans call “inversions,” defined as follows: for a given sequence of positive integers, an inversion is an ordered pair where and . After learning this concept, they compete to see who can first compute the number of inversions in a given sequence of positive integers. Note that the sequence may contain duplicate numbers.
Update: testdata has been strengthened.
Input Format
The first line contains an integer , indicating that the sequence has numbers.
The second line contains integers, representing the given sequence. Each number is at most .
Output Format
Output the number of inversions in the sequence.
6
5 4 2 6 3 1
11
Hint
For 25% of the testdata, .
For 50% of the testdata, .
For all testdata, .
No one should pass on 500,000, right — 2018.8 chen_zhe.
Translated by ChatGPT 5
京公网安备 11011102002149号