Cod sursa(job #1255913)

Utilizator smallOneAdina Mateescu smallOne Data 5 noiembrie 2014 15:55:39
Problema Schi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.62 kb
#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <cstring>
#include <string>
#include <ctime>
#include <cassert>
#include <utility>

#define LIM 30005

using namespace std;

int A[4 * LIM], pos, val, inceput, sfarsit, v[LIM], ocupied[LIM], n;

void updateARB(int nod, int st, int dr) {
    if(st == dr) {
        A[nod] = 1;
        return;
    }
    int m = (st + dr) / 2;
    if(pos <= m)
        updateARB(2 * nod, st, m);
    else
        updateARB(2 * nod + 1, m + 1, dr);
    A[nod] = A[2 * nod] + A[2 * nod + 1];
}

// a k-a pozitie libera
void queryARB(int nod, int st, int dr, int k) {
    if(st == dr) {
        pos = st;
        return;
    }
    int m = (st + dr) / 2;
    int leftk = m - st - A[2 * nod] + 1;
    if(leftk >= k)
        queryARB(2 * nod, st, m, k);
    else
        queryARB(2 * nod + 1, m + 1, dr, k - leftk);
}

int main() {
	freopen("schi.in", "r", stdin);
	freopen("schi.out","w", stdout);

    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &v[i]);
    }

    for(int i = n; i > 0; i--) {
        queryARB(1, 1, n, v[i]);
        int goodPos = pos;
        ocupied[goodPos] = i;
        inceput = 1;
        sfarsit = n;
        pos = goodPos;
        updateARB(1, 1, n);
    }

    for(int i = 1; i <= n; i++) {
        printf("%d\n", ocupied[i]);
    }

	return 0;
}