Cod sursa(job #927064)

Utilizator razvan.popaPopa Razvan razvan.popa Data 25 martie 2013 15:57:41
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include<cstdio>
#define FOR(i,a,b)\
   for(int i=a; i<=b; ++i)
#define FORR(i,a,b)\
   for(int i=a; i>=b; --i)
#define infile "schi.in"
#define outfile "schi.out"
#define zeros(x) (x & -x)
#define nMax 30005
using namespace std;

int V[nMax], Sol[nMax];

int AIB[nMax];

int N;

void read(){
    freopen(infile, "r", stdin);

    scanf("%d", &N);

    FOR(i,1,N)
       scanf("%d", &V[i]);

    fclose(stdin);
}

void update(int x){
    for(; x <= N; x += zeros(x))
        AIB[x] --;
}


int findKthPos(int val){
    int pos, step;
    for(step = 1; step < N; step <<= 1);

    for(pos = 0; step; step >>= 1)
        if(pos + step <= N)
           if(val > AIB[pos + step])
               val -= AIB[pos += step];

    return pos + 1;
}

void solve(){
    FOR(x,1,N)
        AIB[x] = zeros(x);

    FORR(i,N,1){
        int pos = findKthPos(V[i]);

        Sol[pos] = i;

        update(pos);
    }
}

void print(){
    freopen(outfile, "w", stdout);

    FOR(i,1,N)
       printf("%d\n", Sol[i]);

    fclose(stdout);
}

int main(){
    read();
    solve();
    print();

    return 0;
}