Cod sursa(job #2065166)

Utilizator xRoALexBirtoiu Alexandru xRoALex Data 13 noiembrie 2017 15:22:57
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <cstdio>
#include <vector>
using namespace std;

FILE *in=fopen("schi.in","r");
FILE *out=fopen("schi.out","w");

int arb[30005],v[30005],sol[30005],n;
void update(int poz,int val)
{
    while(poz<=n)
    {
        arb[poz]+=val;
        poz+=poz&(-poz);
    }
}

int query(int poz)
{
    int s=0;
    while(poz>0)
    {
        s+=arb[poz];
        poz-=poz&(-poz);
    }
    return s;
}

int cb(int x)
{
    int r=0,pas=1<<15;
    while(pas)
    {
        if(r+pas<=n)
            if(query(r+pas)<x)
                r+=pas;
        pas/=2;
    }
    return r+1;
}

int main()
{
    fscanf(in,"%d",&n);
    for(int i=1;i<=n;i++)
        {
            fscanf(in,"%d",&v[i]);
            update(i,1);
        }
    for(int i=n;i>=1;i--)
    {
        int rez=cb(v[i]);
        sol[rez]=i;
        update(rez,-1);
    }
    for(int i=1;i<=n;i++)
            fprintf(out,"%d\n",sol[i]);
    return 0;
}