#P4402. [CERC2007] robotic sort 机械排序

[CERC2007] robotic sort 机械排序

Description

SORT is a company that provides sorting services with the motto: "Order is the most beautiful." Their job is to arrange certain items in order through a sequence of moves. The work rule allows only the following method to sort:

First find the position of the smallest-labeled item, denoted P1P_1, then reverse the segment [1,P1][1, P_1]. Next find the position of the second smallest item, denoted P2P_2, and reverse the segment [2,P2][2, P_2]... and so on.

The figure shows an example with 66 items. The smallest item is at position 44. Therefore, we first reverse the first 44 items. The second smallest item is at the last position, so the next operation is to reverse items 262 \sim 6. The third step is to reverse items 343 \sim 4...

There may be duplicate labels in the input. If multiple items have the same label, operate on them according to their original input order.

Input Format

The input has two lines. The first line contains an integer N(1N105)N (1 \leq N \leq 10^5), the number of items.

The second line contains NN space-separated integers, the initial labels Ai(0Ai107)A_i (0 \leq A_i \leq 10^7) of the NN items.

Output Format

Output a single line with NN space-separated positive integers P1,P2,P3,PNP_1, P_2, P_3 \cdots, P_N, where PiP_i is the position of the ii-th smallest item before the ii-th operation.

Note: If before the ii-th operation the ii-th smallest item is already at the correct position PiP_i, we reverse the segment [Pi,Pi][P_i, P_i] (a single item).

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

Hint

Translated by ChatGPT 5