Cod sursa(job #3350027)

Utilizator Belea_DariusBelea Mihai Darius Belea_Darius Data 4 aprilie 2026 20:32:20
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <bits/stdc++.h>
#define MAXN 30000

using namespace std;

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

int v[MAXN + 1], aib[MAXN + 1], rez[MAXN + 1], n;

int lsb(int x){
    return x & (-x);
}

void update(int pos, int val){
    while(pos <= n){
        aib[pos] += val;
        pos += lsb(pos);
    }
}

int query(int pos){
    int val = 0;

    while(pos > 0){
        val += aib[pos];
        pos -= lsb(pos);
    }
    return val;
}

int main()
{
    int i, st, dr, mij;

    fin >> n;

    for(i = 1; i <= n; i++){
        fin >> v[i];

        update(i, 1);
    }

    for(i = n; i >= 1; i--){
        st = 0;
        dr = n;
        while(dr - st > 1){
            mij = (dr + st) / 2;

            if(query(mij) >= v[i]){
                dr = mij;
            }else{
                st = mij;
            }
        }
        rez[dr] = i;
        update(dr, -1);
    }

    for(i = 1; i <= n; i++){
        fout << rez[i] << "\n";
    }
    return 0;
}