Cod sursa(job #2020113)

Utilizator rares96cheseliRares Cheseli rares96cheseli Data 9 septembrie 2017 14:07:01
Problema Schi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>

using namespace std;

#define lsb(x) ((-x) & (x))

ifstream f("schi.in");
ofstream g("schi.out");

int N, step, aib[30005], a[30005], sol[300005];

void update(int pos, int val) {
    for (int i = pos; i <= N; i += lsb(i)) {
    	aib[i] += val;
    }
}

int main() {
    f >> N;
    for (int i = 1; i <= N; ++i) {
        f >> a[i];
        update(i, 1);
    }

	for (step = 1; step <= N; step <<= 1);    
    for (int i = N; i; --i) {
        int ps = 0;

        for (int j = step; j; j >>= 1) {
        	if (ps + j <= N && aib[ps + j] < a[i]) {
        		ps += j;
        		a[i] -= aib[ps];
        	}
        }

        sol[ps + 1] = i;
        update(ps + 1, -1);
    }
    
    for (int i = 1; i <= N; ++i) {
        cout << sol[i] << '\n';
    }
    return 0; 
}