Cod sursa(job #3154623)

Utilizator elisa.ipateElisa Ipate elisa.ipate Data 5 octombrie 2023 14:00:07
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <iostream>
#include <fstream>


using namespace std;

#define maxn 30002

int aint[4*maxn], v[maxn], ans[maxn], rez[maxn];

void build( int st, int dr, int poz ) {
    if( st == dr )
        aint[poz] = 1;
    else {
        build( st, (st+dr)/2, 2*poz );
        build( (st+dr)/2 + 1, dr, 2*poz+1 );
        aint[poz] = aint[2*poz] + aint[2*poz+1];
    }
}

void update( int st, int dr, int poz, int vf ) {
    if( st > poz || dr < poz )
        return;
    if( st == dr ) {
        aint[vf] = 0;
        return;
    }
    update( st, (st+dr)/2, poz, 2*vf );
    update( (st+dr)/2 + 1, dr, poz, 2*vf+1 );
    aint[vf] = aint[2*vf] + aint[2*vf+1];
}

int query( int st, int dr, int s, int vf ) {
    if( st == dr )
        return st;
    if( s <= aint[2*vf] )
        return query( st, (st+dr)/2, s, 2*vf );
    return query( (st+dr)/2+1, dr, s-aint[2*vf], 2*vf+1 );

}
int main()
{
    int n, i;
    ifstream cin ("schi.in");
    ofstream cout ("schi.out");
    cin >> n;
    build( 1, n, 1 );
    /*for( i = 1; i <= n; i++ )
        cout << aint[i] << " ";
    cout << "\n";

    update( 1, n, 5, 1 );

    for( i = 1; i <= 4 * n; i++ )
        cout << aint[i] << " ";*/

    for( i = 0; i < n; i++ )
        cin >> v[i];

    for( i = n - 1; i >= 0; i-- ) {
        ans[i] = query( 1, n, v[i], 1 );
        update( 1, n, ans[i], 1 );
        rez[ans[i]] = i+1;
    }

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