#P10522. [XJTUPC 2024] 雪中楼

[XJTUPC 2024] 雪中楼

Problem Description

It snowed at Xi'an Jiaotong University, and all rooftops were covered with snow.

There are nn houses along Wutong Avenue. From south to north, the ii-th house is numbered ii, and all houses have distinct heights. LNC goes from south to north and steps onto the rooftop of each house in order. Then he looks back at the houses he has already visited, and records the index of the tallest house among those that are shorter than the current house. Denote this value as aia_i. In particular, if there is no house shorter than the current one, then ai=0a_i=0.

Now you are given all aia_i. You need to restore the relative height order of all houses. Since the exact heights are unknown, you only need to output the house indices in increasing order of height (from lowest to highest).

It can be proven that for any valid input, there exists a unique solution.

Input Format

The first line contains a positive integer nn (1n2×1051\le n \le 2\times 10^5), representing the number of houses.

The next line contains nn non-negative integers aia_i, satisfying 0ai<i0\le a_i < i, separated by spaces.

Output Format

Output one line containing a permutation of nn positive integers, separated by spaces, representing the final answer.

5
0 0 0 0 2

4 3 2 5 1 

Hint

Assume the heights form a permutation of 1n1 \sim n. Then it can be found that the unique solution is heights 5,3,2,1,45, 3, 2, 1, 4. Outputting the house indices by height rank gives 4,3,2,5,14, 3, 2, 5, 1.

Translated by ChatGPT 5