Cod sursa(job #3367996)

Utilizator RuxandraPro12_Metehau Ruxandra Maria RuxandraPro12_ Data 12 octombrie 2026 17:20:21
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 3e4;

int n, aib[NMAX + 5], clasament_in[NMAX + 5], clasament_f[NMAX + 5];

void update (int poz, int val) {
    while (poz <= n) {
        aib[poz] += val;
        int p2 = (poz & (-poz));
        poz += p2;
    }
}

int cautare_poz (int val) {
    int p2 = 1;
    while (p2 <= n / 2) {
        p2 *= 2;
    }
    int poz = 0;
    while (p2 != 0) {
        if (poz + p2 <= n && aib[poz+p2] < val) {
            poz += p2;
            val -= aib[poz];
        }
        p2 /= 2;
    }
    return poz + 1;
}

int main() {
    fin >> n;
    for (int i = 1; i <= n; i++)
        fin >> clasament_in[i];
    for (int i = 1; i <= n; i++)  
        update (i, 1);
    for (int i = n; i >= 1; i--) {
        int poz_fin = cautare_poz(clasament_in[i]);
        update (poz_fin, -1);
        clasament_f[poz_fin] = i;
    }
    for (int i = 1; i <= n; i++) {
        fout << clasament_f[i] << "\n";
    }
    return 0;
}