Cod sursa(job #854794)

Utilizator alinaelenaFMI Colceag Alina alinaelena Data 14 ianuarie 2013 03:31:03
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include<cstdio>
using namespace std;
# define nmax 100001
int arb[4*nmax+1],maxim,op,poz,a,b,n,m,val,f[30001],v[30001];
 

 
void update (int nod,int st,int dr)
{
    int pivot;
    if (st==dr)
        {arb[nod]=val; return ;}
     
        pivot=(st+dr)/2;
        if (poz<=pivot) update(2*nod,st,pivot);
        else
            update(2*nod+1,pivot+1,dr);
        arb[nod]=arb[2*nod]+arb[2*nod+1];
     
}
 
 
void query (int nod,int st,int dr,int nr)
{
    if (st==dr)
    {  poz=st; return;}
     
    int pivot=(st+dr)/2;
     if (nr<=arb[2*nod]) query(2*nod,st,pivot,nr);
     else query(2*nod+1,pivot+1,dr,nr-arb[2*nod]);
     
}
 
 
int main()
{
    freopen("schi.in","r",stdin);
    freopen("schi.out","w",stdout);
    scanf("%d",&n);
    int i;
	val=1;
     for (i=1;i<=n;++i)
    {
		scanf("%d\n",&v[i]);
		poz=i;
                  update(1,1,n);
    }
     
    for (i=n;i>=1;--i)
    {
             
		query(1,1,n,v[i]);
		
		f[poz]=i;
      val=0;
	  update(1,1,n);
            
    }
	
	for (i=1;i<=n;++i)            
			printf("%d\n",f[i]);
     
}