Pagini recente » Cod sursa (job #287232) | Cod sursa (job #2694894) | Cod sursa (job #137131) | Cod sursa (job #2756268) | Cod sursa (job #1807718)
#include <fstream>
using namespace std;
ifstream fin ("schi.in");
ofstream fout ("schi.out");
#define MAX 30000
int n, v[MAX + 1], ai[MAX * 4 + 1], wn[MAX + 1];
void update(int nod, int l, int r, int pos, int i)
{
int lson = 2 * nod, rson = 2 * nod + 1;
if (l == r)
{
ai[nod] = 1;
wn[l] = i;
return ;
}
int mijl = (l + r) / 2;
if (mijl - l + 1 - ai[lson] >= pos) update(lson, l, mijl, pos, i);
else update(rson, mijl + 1, r, pos - (mijl - l + 1 - ai[lson]), i);
ai[nod] = ai[lson] + ai[rson];
}
int main()
{
fin >> n;
for (int i = 1; i <= n; ++ i)fin >> v[i];
for (int i = n; i >= 1; -- i)
update(1, 1, n, v[i], i);
for (int i = 1; i <= n; ++ i)
fout << wn[i] << '\n';
return 0;
}