Cod sursa(job #2909723)

Utilizator AndreiBOTOBotocan Andrei AndreiBOTO Data 14 iunie 2022 22:01:55
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <iostream>
#include <algorithm>

using namespace std;

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

const int NMAX=3e4+5;
const int NMAX1=1e5+5;

int a[NMAX];
int kon[NMAX];
int lung[NMAX1];

void aint(int p,int st,int dr)
{
    int mij;
    if(st==dr)
    {
        lung[p] = 1;
        return;
    }
    mij=(st+dr) / 2;
    aint(2*p,st,mij);
    aint(2*p+1,mij+1,dr);
    lung[p]=lung[p*2]+lung[2*p+1];
}

void update(int p,int st,int dr,int x,int ok)
{
    int mij;
    if(st==dr)
    {
        lung[p]=0;
        kon[st]=ok;
        return;
    }
    mij=(st+dr)/2;
    if(x<=lung[p*2])
        update(2*p,st,mij,x,ok);
    else
        update(2*p+1,mij+1,dr,x-lung[2*p],ok);
    lung[p]--;
}

int main()
{
    int n,i,j;
    fin>>n;
    for(i=1;i<=n;i++)
        fin>>a[i];
    aint(1,1,n);
    for(i=n;i>=1;i--)
        update(1,1,n,a[i],i);
    for(i=1;i<=n;i++)
        fout<<kon[i]<<"\n";
    return 0;
}