Cod sursa(job #961119)

Utilizator primulDarie Sergiu primul Data 11 iunie 2013 17:17:26
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <cstdio>
 
using namespace std;
   
int v[65001],a[65001],b[65001];
   
int add(int l,int r,int nod,int i)
{
    --a[nod];
    if (l==r) return l;
    if (i<=a[2*nod]) return add(l,(l+r)/2,2*nod,i);
    else return add((l+r)/2+1,r,2*nod+1,i-a[2*nod]);
}
   
int main()
{
    int n,i,x=2;
    freopen("schi.in","r",stdin);
    freopen("schi.out","w",stdout);
    scanf("%d",&n);
    do{
        x*=2;
    }while (x<n);
    for(i=1;i<n+1;i++)
        scanf("%d",&v[i]);
    for(i=x;i<x+n;i++)
        a[i]=1;
    for(i=x-1;i>0;i--)
        a[i]=a[2*i]+a[2*i+1];
    for(i=n;i>0;i--)
        b[add(1,x,1,v[i])]=i;
    for(i=1;i<n+1;i++)
        printf("%d\n",b[i]);
    return 0;
}