Pagini recente » Cod sursa (job #574803) | Cod sursa (job #3149164) | Cod sursa (job #3003206) | Cod sursa (job #383536) | Cod sursa (job #2656443)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("schi.in");
ofstream fout ("schi.out");
void usain_bolt()
{
ios::sync_with_stdio(false);
fin.tie(0);
}
const int N = 3e4 + 5;
int a[N], fen[N], pos[N];
set < int > s;
void update(int node, int val)
{
for(; node <= N - 5; node += node & (-node)) {
fen[node] += val;
}
}
int sum(int node)
{
int sol = 0;
for(; node > 0; node -= node & (-node)) {
sol += fen[node];
}
return sol;
}
int main()
{
usain_bolt();
int n;
fin >> n;
for(int i = 1; i <= n; ++i) {
fin >> pos[i];
s.insert(i);
}
for(int i = n; i >= 1; --i) {
int nr = pos[i] + sum(pos[i]);
update(pos[i], 1);
auto position = lower_bound(s.begin(), s.end(), nr);
a[*position] = i;
s.erase(*position);
}
for(int i = 1; i <= n; ++i) fout << a[i] << "\n";
return 0;
}