Cod sursa(job #2783356)

Utilizator BlueLuca888Girbovan Robert Luca BlueLuca888 Data 14 octombrie 2021 12:10:43
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h>
#define DIM 30005

using namespace std;

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

int n, place[DIM];
int aint[4*DIM], sol[DIM];

void build(int nod, int st, int dr){
    if(st == dr){
        aint[nod]=1;
        return;
    }

    int md=(st+dr)/2;
    build(2*nod, st, md);
    build(2*nod+1, md+1, dr);

    aint[nod] = aint[2*nod] + aint[2*nod+1];
}

void update(int nod, int st, int dr, int poz, int x){
    if(st == dr){
        aint[nod]=0;
        sol[st]=x;
        return;
    }

    int md=(st+dr)/2;
    if(aint[2*nod] >= poz)
        update(2*nod, st, md, poz, x);
    else
        update(2*nod+1, md+1, dr, poz - aint[2*nod], x);

    aint[nod] = aint[2*nod] + aint[2*nod+1];
}

int main (){
    fin>>n;
    for(int i=1; i<=n; i++)
        fin>>place[i];

    build(1, 1, n);

    for(int i=n; i>=1; i--)
        update(1, 1, n, place[i], i);

    for(int i=1; i<=n; i++)
        fout<<sol[i]<<"\n";
    return 0;
}