CF-1208D-线段树和树状数组双解

这篇博客介绍了如何使用线段树和树状数组解决恢复隐藏的长度为n的排列问题。通过分析输入的s数组,确定每个位置上的元素,线段树用于查询区间最小值,树状数组则用来维护未确定位置的数的前缀和,从而找到正确位置。博主提供了清晰的思路和解题方法。
摘要由CSDN通过智能技术生成

An array of integers p 1 , p 2 , … , p n p_1,p_2,…,p_n p1,p2,,pn is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2],[1],[1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2],[1,1],[2,3,4].

There is a hidden permutation of length n.

For each index i, you are given si, which equals to the sum of all pj such that j<i and pj<pi. In other words, si is the sum of elements before the i-th element that are smaller than the i-th element.

Your task is to restore the permutation.

Input
The first line contains a single integer n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 ) n (1≤n≤2⋅10^5) n(1n2105)— the size of the permutation.

The second line contains n integers s 1 , s 2 , … , s n ( 0 ≤ s i ≤ n ( n − 1 ) / 2 ) s_1,s_2,…,s_n(0≤si≤n(n−1)/2) s1,s2,,sn(0sin(n1)/2).

It is guaranteed that the array s corresponds to a valid permutation of length n.

Output
Print n integers p 1 , p 2 , … , p n p_1,p_2,…,p_n p1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值