Permutation Restoration
Time limit0.55sMemory limit128 MB
Given the inversion sequence of a permutation of 1..N, reconstruct the original permutation using an efficient data structure.
- Level
Medium6 of 10
- Topics
- Segment tree, Binary search, Greedy, Array
- Solved
- No attempts yet
Problem
There is a permutation containing each integer from 1 to N exactly once. For each value i, the i-th value of its inversion sequence is the number of values smaller than i that appear to the right of i in the permutation.
For example, the permutation 2 4 5 1 7 6 3 8 has inversion sequence 0 1 0 2 2 1 2 0.
Given an inversion sequence, write a program that restores the corresponding permutation.
Input
The first line contains the size N of the permutation. (1 <= N <= 100,000)
The second line contains the inversion sequence for the values 1, 2, ..., N, separated by spaces.
Output
Print the permutation corresponding to the given inversion sequence on one line, with values separated by spaces.