#P3165. [CQOI2014] 排序机械臂

[CQOI2014] 排序机械臂

Description

To sort items of varying heights in nondecreasing order, engineers invented a sorting robotic arm. It follows a simple rule: in the first operation, find the position P1P_1 of the lowest item and reverse the items from the first item from the left up to P1P_1 (i.e., reverse the subarray [1,P1][1, P_1]); in the second operation, find the position P2P_2 of the second lowest item and reverse the items from the second item from the left up to P2P_2 (i.e., reverse the subarray [2,P2][2, P_2]); and so on. Eventually, all items will be sorted.

样例说明

The figure above shows an example with six items. Before the first operation, the lowest item is at position 44, so the first through fourth items are reversed. Before the second operation, the second lowest item is at position 66, so the second through sixth items are reversed.

Your task is to write a program to determine the sequence of operations, namely, the position PiP_i of the ii-th lowest item before each operation, so the robotic arm can execute them. Note that if there are items with equal height, their relative order must remain the same after sorting.

Input Format

The first line contains a positive integer nn, the number of items to sort.

The second line contains nn space-separated integers PiP_i, the height of each item.

Output Format

Output one line containing nn space-separated integers PiP_i.

6
3 4 5 1 6 2
4 6 4 5 6 6

Hint

N100000N \le 100000

Pi107P_i \le 10^7

Translated by ChatGPT 5