Pagini recente » Cod sursa (job #327205) | Cod sursa (job #441823) | Cod sursa (job #3168028) | Cod sursa (job #2315507) | Cod sursa (job #3134565)
#include <fstream>
#define DIM 30000
using namespace std;
ifstream fin("schi.in");
ofstream fout("schi.out");
int n, v[DIM+1], aib[DIM+1], ans[DIM+1];
int lsb(int x) {
return x & (-x);
}
int query(int pos) {
int ans = 0;
while(pos) {
ans += aib[pos];
pos -= lsb(pos);
}
return ans;
}
void update(int pos, int val) {
while(pos <= n) {
aib[pos] += val;
pos += lsb(pos);
}
}
int cb(int x) {
int pw = 1, pos = 0;
while(pw <= n)
pw *= 2;
pw /= 2;
while(pw) {
if(pos + pw <= n)
if(query(pos + pw) < x)
pos += pw;
pw /= 2;
}
return pos + 1;
}
int main()
{
fin >> n;
for(int i=1; i<=n; i++) {
fin >> v[i];
update(i, 1);
}
for(int i=n; i>=1; i--) {
int rez = cb(v[i]);
ans[rez] = i;
update(rez, -1);
}
for(int i=1; i<=n; i++)
fout << ans[i] << '\n';
return 0;
}