#DSU0000088. Sắp xếp đồng xu (Sorting the Coins)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sắp xếp đồng xu (Sorting the Coins)
Sorting the Coins
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are coins in a row, each of type (out of circulation) or (in circulation). A correctly sorted row contains all coins before all coins.
In one scan, inspect adjacent pairs from left to right. Whenever an pair is found, swap it to and continue scanning. Repeat scans until a scan has no swaps. The sorting hardness is the total number of scans, including the final scan with no swaps.
Initially all coins are . At step , the coin at position is replaced with type ; all positions are distinct. Find the sorting hardness initially and after every replacement. The scans are hypothetical and do not modify the actual row between replacement steps.
Input
The first line contains . The second line is the permutation .
Output
Print integers: the sorting hardness initially and after each replacement.
Subtasks
- Subtask 1 (20 points): ; là hoán vị của .
- Subtask 2 (30 points): ; là hoán vị của .
- Subtask 3 (50 points): ; là hoán vị của .
Example
Input
4
1 3 4 2
Output
1 2 3 2 1
Explanation
Initially all coins are , so one scan suffices. After replacing positions in order, the hardness values are .