Pagini recente » Cod sursa (job #758914) | Statistici Gogelescu Karlos Gabriel (Karlos) | Istoria paginii runda/sim10_3/clasament | Profil 9sophiec292ytjfe0 | Cod sursa (job #2020107)
#include <bits/stdc++.h>
using namespace std;
ifstream f("schi.in");
ofstream g("schi.out");
int N, step = 1, aib[30005], a[30005], sol[300005];
int lsb(int x) {
return -x & x;
}
void update(int pos, int value) {
while (pos <= N) {
aib[pos] += value;
pos += lsb(pos);
}
}
int query(int pos) {
int res = 0;
while (pos) {
res += aib[pos];
pos -= lsb(pos);
}
return res;
}
int main() {
f >> N;
for (int i = 1; i <= N; ++i) {
f >> a[i];
update(i, 1);
}
for (; step <= N; step <<= 1);
for (int i = N; i > 0; --i) {
int ps = 0;
for (int j = step; j; j >>= 1) {
if (ps + j <= N && aib[ps + j] < a[i]) {
ps += j;
a[i] -= aib[ps];
}
}
sol[ps + 1] = i;
update(ps + 1, -1);
}
for (int i = 1; i <= N; ++i) {
cout << sol[i] << '\n';
}
return 0;
}