Cod sursa(job #3332334)

Utilizator AndreiNicolaescuEric Paturan AndreiNicolaescu Data 6 ianuarie 2026 10:08:31
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <bits/stdc++.h>
#define cin ci
#define cout co
#define int long long
using namespace std;
ifstream cin("schi.in");
ofstream cout("schi.out");

const int Nmax = 3e5;
int n, aib[Nmax + 5], sol[Nmax + 5], v[Nmax + 5];

void update(int p, int val)
{
    for (; p <= n; p += p & -p)
        aib[p] += val;
}

int bs(int val)
{
    int sum = 0, pos = 0;
    for (int step = 1 << 19; step; step >>= 1)
        if (pos + step <= n && sum + aib[pos + step] < val)
        {
            pos += step;
            sum += aib[pos];
        }
    return pos + 1;
}

int32_t main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> v[i];


    for(int i = 1; i <= n; i++)
        update(i, 1);

    for(int i = n; i >= 1; i--)
    {
        int p = bs(v[i]);
        sol[p] = i;
        update(p, -1);
    }

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