Cod sursa(job #2761737)

Utilizator bestman4111Tiberiu Niculae bestman4111 Data 3 iulie 2021 20:15:19
Problema Schi Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include<iostream>
#include<fstream>
using namespace std;

ifstream cit("schi.in");
ofstream afis("schi.out");

int N, v[30001], rez[30001], temp[60001];

void refac_clasament(int poz, int prez, int st, int dr, int nr){
    int mij;
    if(st == dr){
        temp[poz] = 1;
        rez[st] = prez;
        return;
    }
    mij = (st + dr)/2;
    if(nr <= mij - st + 1 - temp[2 * poz]){
        refac_clasament(2 * poz, prez, st, mij, nr);
    }
    else{
        refac_clasament(2 * poz + 1, prez, mij + 1, dr, nr - mij + st - 1 + temp[2 * poz]);
    }
    temp[poz] = temp[2 * poz] + temp[2 * poz + 1];
}

int main()
{
    cit>>N;
    for(int i = 1; i <= N; i++){
        cit>>v[i];
    }
    for(int i = N; i >= 1; i--){
        refac_clasament(1, i, 1, N, v[i]);
    }
    for(int i = 1; i <= N; i++){
        afis<<rez[i]<<"\n";
    }
    return 0;
}