#P6278. [USACO20OPEN] Haircut G
[USACO20OPEN] Haircut G
Description
Farmer John is tired of trying to straighten his unruly hair, so he decides to get a haircut. He has a row of strands of hair, and the -th strand initially has length micrometers (). Ideally, he wants his hair lengths to be monotonically non-decreasing, so he defines the “badness” of his hair as the number of inversions: pairs such that and .
For each , Farmer John wants to know the badness of his hair if all strands with length greater than are reduced to length .
(Fun fact: Humans really do have about hairs on average!)
Input Format
The first line contains .
The second line contains .
Output Format
For each , output on a separate line the badness of Farmer John’s hair.
Note that the integer values in this problem may require 64-bit integer storage (for example, “long long” in C/C++).
5
5 2 3 3 0
0
4
4
5
7
Hint
Sample Explanation:
The fourth line of the output describes the number of inversions when Farmer John’s hair lengths are reduced to .
has five inversions: , , , , and .
For of the testdata, .
There are test points in total. Test point is the sample, and the others satisfy:
Test point satisfies .
Test points satisfy .
Test points have no additional constraints.
Problem author: Dhruv Rohatgi.
Translated by ChatGPT 5
京公网安备 11011102002149号