Cod sursa(job #3361007)

Utilizator AndreiNicolaescuEric Paturan AndreiNicolaescu Data 18 iulie 2026 14:56:10
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <bits/stdc++.h>
#define int long long
#define cin ci
#define cout co
using namespace std;
ifstream cin("schi.in");
ofstream cout("schi.out");
const int nmax = 30000;
int n;
vector<int> v;
int aib[nmax + 5];
void update(int pos, int val)
{
    for(; pos <= n; pos += pos & (-pos))
        aib[pos] += val;
}
int bs(int val)
{
    int cur = 0, sum = 0;
    for(int step = (1 << 20); step > 0; step >>= 1)
        if(cur + step <= n && aib[cur + step] < val)
        {
            cur += step;
            val -= aib[cur];
        }
    return cur + 1;
}
int32_t main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n;
    v.resize(n + 5);
    for(int i = 1; i <= n; i ++)
        update(i, 1);
    for(int i = 1; i <= n; i ++)
        cin >> v[i];

    vector<int> res(n + 5, 0);
    for(int i = n; i >= 1; i --)
    {
        int pos = bs(v[i]);
        res[pos] = i;
        update(pos, -1);
    }
    for(int i = 1; i <= n; i ++)
        cout << res[i] << '\n';
    return 0;
}