#FT0000071. Sắp xếp Turbo (Turbo)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sắp xếp Turbo (Turbo)
Turbo
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Frane is given a permutation containing every integer from to exactly once. He wants to sort it in increasing order by a fixed procedure of exactly phases.
In phase one, he moves value to the first position using swaps of adjacent elements. In phase two, he moves value to the last position. Phase three moves value to the second position, phase four moves value to position , and so on, alternately fixing the smallest and largest values not fixed yet. Once an element reaches its final position, later phases leave it in place.
For each phase, determine the number of adjacent swaps required, in chronological order. Print when the selected element is already in its final position.
Input
The first line contains integer .
Exactly lines follow; line contains integer , the original value at position .
Output
Print exactly lines. Line contains the number of adjacent swaps performed during phase .
Subtasks
-
Subtask 1 (20 points): ; ; each integer from to occurs exactly once.
-
Subtask 2 (30 points): ; ; each integer from to occurs exactly once.
-
Subtask 3 (50 points): ; ; each integer from to occurs exactly once.
Examples
Input
3
2
1
3
Output
1
0
0
Explanation
Initially the permutation is .
- Phase 1: Value is at position . Swap it with , producing in one swap.
- Phase 2: Value is already last, requiring zero swaps.
- Phase 3: Value is already second, requiring zero swaps.
The three lines are therefore 1, 0, and 0.