P5463 Little Fish Compare Cuteness (Enhanced Version).
Description
When people compare with each other, it is annoying; when fish compare with each other, it is even worse. Little Fish recently joined a “cuteness comparison” contest, where the cuteness of each fish is compared. The fish are lined up from left to right, all facing to the left. Then each fish is given an integer value representing its cuteness. Obviously, the larger the integer is, the cuter the fish is, and any two fish may have the same cuteness value. Since all fish face left, each fish can only see the cuteness values of the fish to its left. They are all calculating in their minds: within their view, how many fish are less cute than themselves? Please help these cute little fish, whose brains are not good enough, compute this.
Different from the previous requirement, the organizing committee cares about the “total smugness value” of this arrangement. There are $n$ little fish, and there are $\frac{n(n+1)}2$ different intervals in total. The smugness value of each interval equals the number of pairs in this interval that satisfy “the fish on the left has a larger cuteness value than the fish on the right” (in fact, it is the number of inversions in the interval). The total smugness value is the sum of the smugness values of all intervals. Now you need to output what the “total smugness value” is.
Input Format
The first line contains an integer $n$, representing the number of fish.
The second line contains $n$ integers $a_1,a_2,\cdots,a_n$, separated by spaces, representing the cuteness of each little fish from left to right.
Output Format
Output one integer representing the answer.
Explanation/Hint
Test Point | $n$ | $a_i$ | Are there duplicate numbers
:-:|:-:|:-:|:-:
$1$ | $1$ | No special restrictions | No
$2$ | $10$ | No special restrictions | No
$3$ | $10$ | No special restrictions | Yes
$4$ | $1000$ | $\le10$ | Yes
$5$ | $1000$ | No special restrictions | No
$6$ | $1000$ | No special restrictions | Yes
$7$ | $10^5$ | $\le100$ | Yes
$8$ | $3\times 10^5$ | No special restrictions | No
$9$ | $5\times 10^5$ | No special restrictions | Yes
$10$ | $10^6$ | No special restrictions | Yes
Constraints: for $100\%$ of the data, $n \le 10^6$, $a_i \le 10^9$, and all numbers are non-negative integers.
Translated by ChatGPT 5