Cod sursa(job #3338891)

Utilizator bulatalexandrinaAlexandrina Bulat bulatalexandrina Data 5 februarie 2026 13:08:36
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <fstream>
using namespace std;

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

int n;
int c[30001];
int sol[30001];
int arb[120001];

void construieste(int st, int dr, int nod)
{
    if (st == dr)
    {
        arb[nod] = 1;
        return;
    }
    int mij = (st + dr) / 2;
    construieste(st, mij, 2 * nod);
    construieste(mij + 1, dr, 2 * nod + 1);
    arb[nod] = arb[2 * nod] + arb[2 * nod + 1];
}

int cauta_pozitie(int st, int dr, int nod, int k)
{
    if (st == dr)
        return st;
    int mij = (st + dr) / 2;
    if (arb[2 * nod] >= k)
        return cauta_pozitie(st, mij, 2 * nod, k);
    else
        return cauta_pozitie(mij + 1, dr, 2 * nod + 1, k - arb[2 * nod]);
}

void modifica(int st, int dr, int nod, int poz)
{
    if (st == dr)
    {
        arb[nod] = 0;
        return;
    }
    int mij = (st + dr) / 2;
    if (poz <= mij)
        modifica(st, mij, 2 * nod, poz);
    else
        modifica(mij + 1, dr, 2 * nod + 1, poz);
    arb[nod] = arb[2 * nod] + arb[2 * nod + 1];
}

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

    construieste(1, n, 1);

    for (int i = n; i >= 1; i--)
    {
        int poz = cauta_pozitie(1, n, 1, c[i]);
        sol[poz] = i;
        modifica(1, n, 1, poz);
    }

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

    fin.close();
    fout.close();
    return 0;
}