An array of integers p 1 ,p 2 ,…,p n
p1,p2,…,pn
is called a permutation if it contains each number from 1
1
to n
n
exactly once. For example, the following arrays are permutations: [3,1,2],[1],[1,2,3,4,5]
[3,1,2],[1],[1,2,3,4,5]
and [4,3,1,2]
[4,3,1,2]
. The following arrays are not permutations: [2],[1,1],[2,3,4]
[2],[1,1],[2,3,4]
.
There is a hidden permutation of length n
n
.
For each index i
i
, you are given s i
si
, which equals to the sum of all p j
pj
such that j<i
j<i
and p j <p i
pj<pi
. In other words, s i
si
is the sum of elements before the i
i
-th element that are smaller than the i
i
-th element.
Your task is to restore the permutation.
这个的题意就是给你一个s数组 si表示就是第i个数前面比它小的数的和为多少
这个的思路就是从最后一个开始考虑 因为可以很容易的求出最后一位是多少
然后把最后以为的影响消除掉
可以知道最后一位