Cod sursa(job #777651)

Utilizator ionut_blesneagIonut Blesneag ionut_blesneag Data 12 august 2012 22:43:44
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include<cstdio>
using namespace std;

int n,i,val,poz,a[30005],ranking[30005],rez;
int tree[1<<16+1];

void update(int nod, int left, int right)
{if(left==right)
   {tree[nod]=val;
    return;}
 int mij=(left+right)/2;  
 if(poz<=mij)
    update(2*nod, left, mij);
 else
    update(2*nod+1, mij+1, right);
 tree[nod]=tree[2*nod+1]+tree[2*nod];        
}

void query(int nod, int left, int right)
{if(left==right)
   {rez=left;
    return;}
 int mij=(left+right)/2;
 if(val<=tree[2*nod])
   query(2*nod,left,mij);
 else
   {val=val-tree[2*nod];
    query(2*nod+1,mij+1,right);}  
}

int main()
{
freopen("schi.in","r",stdin);
freopen("schi.out","w",stdout);
scanf("%d",&n);
for(i=1; i<=n; i++)
  {poz=i;
   val=1;
   update(1,1,n);
   scanf("%d",&a[i]);}   
   
for(i=n; i>=1; i--)
  {val=a[i];
   query(1,1,n);
   ranking[rez]=i;
   poz=rez;
   val=0;
   update(1,1,n);
   }    
   
for(i=1; i<=n; i++)
  printf("%d\n",ranking[i]);   

return 0;}