Cod sursa(job #1155727)

Utilizator CostanMiriamCostan Miriam CostanMiriam Data 27 martie 2014 09:35:52
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>

using namespace std;

ifstream fin ("schi.in");
ofstream fout ("schi.out");

int v[30005],w[4*30001],a[30005],n,i,loc;

void update (int nod, int st, int dr ) {
    if (st==dr) {
        w[nod]=1;
        return;
    }
    int mid = (st+dr)/2;
    if (i<=mid)
        update (2*nod,st,mid);
    else
        update (2*nod+1,mid+1,dr);

    w[nod]=w[2*nod]+w[2*nod+1];
}

void update2 (int nod, int st, int dr, int x) {
    if (st==dr) {
        w[nod]=0;
        loc=st;
        return;
    }
    int mid =(st+dr)/2;
    if (x<=w[2*nod])
        update2 (2*nod, st, mid, x);
    else
        update2 (2*nod+1, mid+1, dr, x-w[2*nod]);

    w[nod]=w[2*nod]+w[2*nod+1];
}

int main () {

    fin>>n;
    for (i=1;i<=n;i++)
        fin>>v[i];

    for (i=1;i<=n;i++)
        update (1,1,n);

    for (i=n;i>=1;i--) {
        update2 (1,1,n,v[i]);
        a[loc]=i;
    }
    for (i=1;i<=n;i++)
        fout<<a[i]<<"\n";

    return 0;
}