P10522 [XJTUPC 2024] Snowy Rooftops

Description

It snowed at Xi'an Jiaotong University, and all rooftops were covered with snow. There are $n$ houses along Wutong Avenue. From south to north, the $i$-th house is numbered $i$, 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 $a_i$. In particular, if there is no house shorter than the current one, then $a_i=0$. Now you are given all $a_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 $n$ ($1\le n \le 2\times 10^5$), representing the number of houses. The next line contains $n$ non-negative integers $a_i$, satisfying $0\le a_i < i$, separated by spaces.

Output Format

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

Explanation/Hint

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