You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
const int N = 100010;
|
|
|
|
|
int a[N];
|
|
|
|
|
int ans[N];
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
// 树状数组模板
|
|
|
|
|
typedef long long LL;
|
|
|
|
|
#define lowbit(x) (x & -x)
|
|
|
|
|
int c[N];
|
|
|
|
|
void add(int x, int d) {
|
|
|
|
|
for (int i = x; i < N; i += lowbit(i)) c[i] += d;
|
|
|
|
|
}
|
|
|
|
|
LL sum(int x) {
|
|
|
|
|
LL res = 0;
|
|
|
|
|
for (int i = x; i; i -= lowbit(i)) res += c[i];
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
参考答案:
|
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
|
|
3
|
|
|
|
|
1
|
|
|
|
|
*/
|
|
|
|
|
int main() {
|
|
|
|
|
#ifndef ONLINE_JUDGE
|
|
|
|
|
freopen("244.in", "r", stdin);
|
|
|
|
|
#endif
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
for (int i = 2; i <= n; i++) scanf("%d", &a[i]); // 读入每头奶牛前面有几头奶牛比自己矮
|
|
|
|
|
|
|
|
|
|
// 这里是区别!
|
|
|
|
|
// 利用树状数组,把1~n之间每个位置设置为1,方便后面用来求前缀和
|
|
|
|
|
// for (int i = 1; i <= n; i++) add(i, 1);
|
|
|
|
|
|
|
|
|
|
for (int i = n; i; i--) {
|
|
|
|
|
int l = 1, r = n;
|
|
|
|
|
while (l < r) { // 用二分找出前缀和恰好为a[i] + 1的数
|
|
|
|
|
|
|
|
|
|
// 这里是区别!
|
|
|
|
|
int mid = (l + r) >> 1; // mid枚举的是下标
|
|
|
|
|
if (mid - sum(mid) >= a[i] + 1)
|
|
|
|
|
r = mid; // 再小点试试
|
|
|
|
|
else
|
|
|
|
|
l = mid + 1; // 再大点~
|
|
|
|
|
}
|
|
|
|
|
ans[i] = l; // 记录答案
|
|
|
|
|
add(l, 1); // 找到后,这个数-1,标识为0,方便下次求前缀和
|
|
|
|
|
}
|
|
|
|
|
// 输出结果
|
|
|
|
|
for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|