Cod sursa(job #3245961)

Utilizator Mihai_AritonMihai Ariton Mihai_Ariton Data 1 octombrie 2024 11:46:37
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h>
using namespace std;

int v[30005], st[400005], a[30005];
void build(int node, int l, int r)
{
    int mij;
    if(l==r)
    {
        st[node]=1;
        return;
    }
    else
    {
        mij=(l+r)/2;
        build(node*2, l, mij);
        build(node*2+1, mij+1, r);
        st[node]=st[node*2]+st[node*2+1];
    }
}
void update(int node, int l, int r, int poz, int val)
{
    int mij;
    if(l==r)
    {
        st[node]=0;
        a[l]=val;
        return;
    }
    mij=(l+r)/2;
    if(st[node*2]>=poz)
    update(node*2, l, mij, poz, val);
    else
    update(node*2+1, mij+1, r, poz-st[node*2], val);
    st[node]=st[node*2]+st[node*2+1];
}
int main()
{
    ifstream cin("schi.in");
    ofstream cout("schi.out");

    int n;
    cin>>n;
    build(1, 1, n);
    for(int i=1; i<=n; i++)
        cin>>v[i];
    for(int i=n; i>=1; i--)
        update(1, 1, n, v[i], i);
    for(int i=1; i<=n; i++)
        cout<<a[i]<<'\n';

    return 0;
}