Score : 600 points
Problem Statement
Given is a sequence A=[a0,a1,a2,…,aN−1] that is a permutation of 0,1,2,…,N−1.
For each k=0,1,2,…,N−1, find the inversion number of the sequence B=[b0,b1,b2,…,bN−1] defined as bi=ai+kmodN.
What is inversion number?
The inversion number of a sequence A=[a0,a1,a2,…,aN−1] is the number of pairs of indices (i,j) such that i<j and ai>aj.
Constraints
- All values in input are integers.
- 2≤N≤3×105
- a0,a1,a2,…,aN−1 is a permutation of 0,1,2,…,N−1.
Input is given from Standard Input in the following format:
N
a0 a1 a2 ⋯ aN−1
Output
Print N lines.
The (i+1)-th line should contain the answer for the case k=i.
4
0 1 2 3
0
3
4
3
We have A=[0,1,2,3].
For k=0, the inversion number of B=[0,1,2,3] is 0.
For k=1, the inversion number of B=[1,2,3,0] is 3.
For k=2, the inversion number of B=[2,3,0,1] is 4.
For k=3, the inversion number of B=[3,0,1,2] is 3.
10
0 3 1 5 4 2 9 6 8 7
9
18
21
28
27
28
33
24
21
14