可以利用区间的性质进行二分,区间的信息用树状数组维护 O(nlog²n)
#include<bits/stdc++.h>
#define LL long long
#define x first
#define y second
#define de(x) cout<<#x<<" = "<<x<<" "
#define deg(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int N=1e5+10;
typedef pair<int,int> PII;
int n;
int a[N],tr[N],ans[N];
int lowbit(int x)
{
return x&-x;
}
void add(int x,int c)
{
for(int i=x;i<=n;i+=lowbit(i))tr[i]+=c;
}
int sum(int x)
{
int res=0;
for(int i=x;i;i-=lowbit(i))res+=tr[i];
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=2;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)tr[i]=lowbit(i);
for(int i=n;i;i--)
{
int k=a[i]+1;
int l=0,r=n+1;
while(l+1!=r)
{
int mid=l+r>>1;
if(sum(mid)>=k)r=mid;
else l=mid;
}
ans[i]=r;
add(r,-1);
}
for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
return 0;
}