#P5463. 小鱼比可爱(加强版)

小鱼比可爱(加强版)

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 nn little fish, and there are n(n+1)2\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 nn, representing the number of fish.

The second line contains nn integers a1,a2,,ana_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.

8
1 9 2 6 0 8 1 7
106
10
1 10 8 5 6 2 3 9 4 7
270
20
6 0 4 5 8 8 0 6 6 1 0 4 6 6 0 0 7 2 0 5
3481

Hint

Test Point nn aia_i Are there duplicate numbers
11 No special restrictions No
22 1010
33 Yes
44 10001000 10\le10
55 No special restrictions No
66 Yes
77 10510^5 100\le100
88 3×1053\times 10^5 No special restrictions No
99 5×1055\times 10^5 Yes
1010 10610^6

Constraints: for 100%100\% of the data, n106n \le 10^6, ai109a_i \le 10^9, and all numbers are non-negative integers.

Translated by ChatGPT 5