Cod sursa(job #2563482)

Utilizator AlexPascu007Pascu Ionut Alexandru AlexPascu007 Data 1 martie 2020 11:54:20
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <bits/stdc++.h>
#define DIM 30010
using namespace std;
ifstream fin("schi.in");
ofstream fout("schi.out");
int n,i,v[DIM],sol[DIM],A[3*DIM];
void build(int nod,int st,int dr) {
    if (st==dr)
        A[nod]=1;
    else {
        int mid=(st+dr)/2;
        build(2*nod,st,mid);
        build(2*nod+1,mid+1,dr);
        A[nod]=A[2*nod]+A[2*nod+1];
    }
}
void update(int nod,int st,int dr,int x,int poz) {
    if (st==dr) {
        A[nod]=0;
        sol[st]=x;
    }
    else {
        int mid=(st+dr)/2;
        if (A[2*nod]>=poz)
            update(2*nod,st,mid,x,poz);
        else
            update(2*nod+1,mid+1,dr,x,poz-A[2*nod]);
        A[nod]=A[2*nod]+A[2*nod+1];
    }
}
int main() {
    fin>>n;
    for (i=1;i<=n;i++)
        fin>>v[i];
    build(1,1,n);
    for (i=n;i>=1;i--)
        update(1,1,n,i,v[i]);
    for (i=1;i<=n;i++)
        fout<<sol[i]<<"\n";
    return 0;
}