Cod sursa(job #3185507)

Utilizator calin06calin mihaescu calin06 Data 19 decembrie 2023 10:53:26
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("schi.in");
ofstream fout("schi.out");

const int nmax = 30010;
int a[nmax], arb[4 * nmax], n, sol[nmax];

void build(int nod, int st, int dr)
{
    if (st == dr)
        arb[nod] = 1;
    else
    {
        int mid = (st + dr) / 2;
        build(2 * nod, st, mid);
        build(2 * nod + 1, mid + 1, dr);
        arb[nod] = arb[2 * nod] + arb[2 * nod + 1];
    }
}

int update(int nod, int st, int dr, int val, int poz)
{
    if (st == dr)
    {
        sol[st] = poz;
        arb[nod] = 0;
        return arb[nod];
    }
    else
    {
        int mid = (st + dr) / 2;
        if (arb[2 * nod] >= val)
        {
            
            arb[nod] = update(2 * nod, st, mid, val, poz) + arb[2 * nod + 1];
        }
        else
        {
            arb[nod] =  update(2 * nod + 1,mid + 1,dr,val - arb[nod * 2],poz) + arb[2 * nod];
        }
        return arb[nod];
    }
}

int main()
{
    fin >> n;
    for (int i = 1; i <= n; i++)
        fin >> a[i];

    build(1, 1, n);

    for(int i = n;i >= 1;i--)
        update(1,1,n,a[i],i);

    for(int i = 1;i <= n;i++)
        fout<<sol[i]<<"\n";
}