392 传统题

[ABC190F] 循环移位与逆序对 (Shift and Inversions)

时间限制
2000ms
内存限制
1024MiB
登顶 / 尝试
0/ 0
难度
5
    上传者 标签AtCoderABC190提高-树状数组逆序对

[ABC190F] 循环移位与逆序对 (Shift and Inversions)

Score : 600600 points

Problem Statement

Given is a sequence A=[a0,a1,a2,…,aN−1]A = [a_0, a_1, a_2, \dots, a_{N-1}] that is a permutation of 0,1,2,…,N−10, 1, 2, \dots, N - 1.

For each k=0,1,2,…,N−1k = 0, 1, 2, \dots, N - 1, find the inversion number of the sequence B=[b0,b1,b2,…,bN−1]B = [b_0, b_1, b_2, \dots, b_{N-1}] defined as bi=ai+k mod Nb_i = a_{i+k \bmod N}.

What is inversion number? The inversion number of a sequence A=[a0,a1,a2,…,aN−1]A = [a_0, a_1, a_2, \dots, a_{N-1}] is the number of pairs of indices (i,j)(i, j) such that iaji a_j.

Constraints

  • All values in input are integers.

  • 2≤N≤3×1052 ≤ N ≤ 3 \times 10^5

  • a0,a1,a2,…,aN−1a_0, a_1, a_2, \dots, a_{N-1} is a permutation of 0,1,2,…,N−10, 1, 2, \dots, N - 1.

Input

Input is given from Standard Input in the following format:

$N$
$a_0$ $a_1$ $a_2$ $\cdots$ $a_{N-1}$

Output

Print NN lines.

The (i+1)(i + 1)-th line should contain the answer for the case k=ik = i.

Sample Input 1

4
0 1 2 3

Sample Output 1

0
3
4
3

We have A=[0,1,2,3]A = [0, 1, 2, 3].

For k=0k = 0, the inversion number of B=[0,1,2,3]B = [0, 1, 2, 3] is 00.

For k=1k = 1, the inversion number of B=[1,2,3,0]B = [1, 2, 3, 0] is 33.

For k=2k = 2, the inversion number of B=[2,3,0,1]B = [2, 3, 0, 1] is 44.

For k=3k = 3, the inversion number of B=[3,0,1,2]B = [3, 0, 1, 2] is 33.

Sample Input 2

10
0 3 1 5 4 2 9 6 8 7

Sample Output 2

9
18
21
28
27
28
33
24
21
14