Cod sursa(job #1354341)

Utilizator horatiu11Ilie Ovidiu Horatiu horatiu11 Data 21 februarie 2015 19:27:55
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
//horatiu11
# include <cstdio>
# define nmax 30001
using namespace std;
int n,a[nmax],arb[4*nmax+1],res[nmax],poz;
inline void make_arb(int nod, int st, int dr)
{
    arb[nod]=dr-st+1;
    if(st==dr)return;
    int m=(st+dr)/2;
    make_arb(nod*2,st,m);
    make_arb(nod*2+1,m+1,dr);
}
inline void result(int nod, int st, int dr, int val)
{
    int m=(st+dr)/2;
    if(st==dr)res[st]=poz;
    else if(arb[2*nod]>=val)result(2*nod,st,m,val);
    else result(2*nod+1,m+1,dr,val-arb[2*nod]);
    arb[nod]--;
}
int main()
{
    int i;
    freopen("schi.in","r",stdin);
    freopen("schi.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;++i)
        scanf("%d",&a[i]);
    make_arb(1,1,n);
    for(i=n;i>0;--i)
    {
        poz=i;
        result(1,1,n,a[i]);
    }
    for(i=1;i<=n;++i)
        printf("%d\n",res[i]);
    return 0;
}