Cod sursa(job #2751153)

Utilizator VladCaloVlad Calomfirescu VladCalo Data 14 mai 2021 13:34:04
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
//
//  main.cpp
//  schi
//
//  Created by Vlad Calomfirescu on 14.05.2021.
//

#include <iostream>
#include <fstream>
 
using namespace std;
ifstream fin("schi.in");
ofstream fout("schi.out");
 
int n, m, val, pos, rez;
int v[30002],sol[30002], a[4 * 30002];
 
 
void update(int nod, int stg, int dr)
{
    if (stg == dr)
    {
        a[nod] = val;
        return;
    }
    int mij = (stg + dr) / 2;
    if (pos <= mij)
        update(2 * nod, stg, mij);
    else
        update(2 * nod + 1, mij + 1, dr);
    a[nod] = a[2*nod]+a[2*nod+1];
}
 
void qr(int nod, int stg, int dr)
{
    if (stg==dr)
    {
        rez = stg;
        return;
    }
    int mij = (stg + dr) / 2;
    if (a[2 * nod] >= val)
        qr(2 * nod, stg, mij);
    else
    {
        val = val - a[2 * nod];
        qr(2 * nod + 1, mij + 1, dr);
    }
}
 
int main()
{
    fin >> n;
    for (int i = 1; i <= n; i++)
    {
        fin >> v[i];
        pos = i;
        val = 1;
        update(1, 1, n);
    }
    for (int i = n; i >= 1; i--)
    {
        rez = 0;
        val = v[i];
        qr(1, 1, n);
        sol[rez] = i;
        pos = rez;
        val = 0;
        update(1, 1, n);
    }
    for (int i = 1; i <= n; i++)
        fout << sol[i] << "\n";
   
    return 0;
}