Cod sursa(job #2954798)

Utilizator PieleVoinescu David Piele Data 15 decembrie 2022 13:12:11
Problema Schi Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define nmax 30005
using namespace std;
ifstream fin("schi.in");
ofstream fout("schi.out");

int n;
int a[nmax];
int rasp[nmax];
int arb[4*nmax];

void pune(int nod,int st,int dr,int pos,int val,int n)
{

    if(st==dr)
    {
        arb[nod]=1;
        rasp[st]=val;
        return;
    }

    int mid=(st+dr)/2;

    if(pos<=n/2-arb[2*nod])
        pune(2*nod,st,mid,pos,val,n/2);
    else
        pune(2*nod+1,mid+1,dr,pos-n/2+arb[2*nod],val,n/2);

    arb[nod]=arb[2*nod]+arb[2*nod+1];
}
///1 1 3 4 4 2 1 3
///7 2 8 6 1 3 5 4
void citire()
{
    fin>>n;
    for(int i=1; i<=n; ++i)
        fin>>a[i];
    for(int i=n; i>=1; i--)
        pune(1,1,n,a[i],i,n);

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

int main()
{
    citire();

    return 0;
}