Cod sursa(job #856138)

Utilizator BalcauIonutFMI-Balcau Ionut BalcauIonut Data 15 ianuarie 2013 23:00:41
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include<fstream>
  
using namespace std;
ifstream f("schi.in");
ofstream g("schi.out");
  
int suma[65600], poz, val;
  
void actualizare(int nod, int st,int dr)
{
    if(st==dr)
        suma[nod]=val;
    else
    {
        int m;
        m=(st+dr)/2;
        if(poz<=m)
            actualizare(nod*2,st,m);
        else
            actualizare(nod*2+1,m+1,dr);
        suma[nod]=suma[nod*2]+suma[nod*2+1];
    }
}
  
void cauta(int nod,int st,int dr,int x)
{
    if(st==dr)
        poz=st;
    else
    { 
        int m;
        m=(st+dr)/2;
        if(x<=suma[nod*2])
            cauta(nod*2,st,m,x);
        else
            cauta(nod*2+1,m+1,dr,x-suma[nod*2]);
    }                 
}
  
int main()
{
    int n,i,cat[30001],loc[30001];
  
    f>>n;
  
    for(poz=1;poz<=n;poz++)
    { 
        val=1;
        actualizare(1,1,n);
        f>>cat[poz];
    }
      
    for(i=n;i>0;i--)
    {  
        cauta(1,1,n,cat[i]);
        loc[poz]=i;
        val=0;
        actualizare(1,1,n);
    }
    for(i=1;i<=n;i++)
        g<<loc[i]<<"\n";
      
    return 0;
}