Pagini recente » Monitorul de evaluare | Cod sursa (job #2020101)
#include <bits/stdc++.h>
using namespace std;
ifstream f("schi.in");
ofstream g("schi.out");
int N, aib[30005], a[30005], sol[300005];
int lsb(int x) {
return -x & x;
}
void update(int pos, int val) {
for (; pos <= N; pos += lsb(pos)) {
aib[pos] += val;
}
}
int query(int pos) {
int res = 0;
for (; pos; pos -= lsb(pos)) {
res += aib[pos];
}
return res;
}
int main() {
f >> N;
for (int i = 1; i <= N; ++i) {
f >> a[i];
update(i, 1);
}
for (int i = N; i > 0; --i) {
int ps = 0, step = 1;
for (; step <= N; step <<= 1);
for (; step; step >>= 1) {
if (ps + step <= N && query((ps + step)) <= a[i] - 1) {
ps += step;
}
}
sol[ps + 1] = i;
update(ps + 1, -1);
}
for (int i = 1; i <= N; ++i) {
cout << sol[i] << '\n';
}
return 0;
}