Cod sursa(job #1807718)

Utilizator ancabdBadiu Anca ancabd Data 16 noiembrie 2016 21:07:06
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#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;
}