#FT0000064. Nghịch thế sau mỗi phép quay trái (Shift and Inversions)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nghịch thế sau mỗi phép quay trái (Shift and Inversions)
Shift and Inversions
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a permutation of the integers through . Each integer occurs once.
For every from to , form the left-rotated sequence with .
An inversion is a pair of positions whose values satisfy . Compute the inversion count of each of the rotations of the original sequence, in increasing order of .
Input
The first line contains .
The second line contains integers forming a permutation of .
Output
Print exactly lines. Line contains the inversion count of the left rotation by positions, for .
Subtasks
-
Subtask 1 (20 points): ; is a permutation of .
-
Subtask 2 (30 points): ; is a permutation of .
-
Subtask 3 (50 points): ; is a permutation of .
Examples
Input
4
0 1 2 3
Output
0
3
4
3
Explanation
Consider each rotation separately:
- : has inversions.
- : has inversions, all ending at .
- : has inversions: , , , .
- : has inversions, all starting at .
The printed counts are 0, 3, 4, 3.