Cod sursa(job #3332223)

Utilizator InformaticianInDevenire1Munteanu Mihnea Gabriel InformaticianInDevenire1 Data 5 ianuarie 2026 11:33:45
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <bits/stdc++.h>
#define int long long

using namespace std;

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

int aib[30005];
int v[30005];
int ans[30005];
int n;

int LSB(int x){
    return (x&(-x));
}

int Query(int pos){
    int ans = 0;
    for (int i=pos;i>0;i-=LSB(i)){
        ans += aib[i];
    }
    return ans;
}

void Update(int pos,int val){
    for (int i=pos;i<=n;i+=LSB(i)){
        aib[i] += val;
    }
}

int BinarySearch(int a){
    int L = 1,R = n;
    while (L<R){
        int M = (L+R)/2;
        if (Query(M)>=a) R = M;
        else L = M+1;
    }
    return L;
}

signed main()
{
    fin >> n;
    for (int i=1;i<=n;++i){
        fin >> v[i];
        Update(i,1);
    }
    for (int i=n;i>=1;--i){
        int ind = BinarySearch(v[i]);
        Update(ind,-1);
        ans[ind] = i;
        //cout << i << ' ' << ind << '\n';
    }
    for (int i=1;i<=n;++i){
        fout << ans[i] << '\n';
    }
    return 0;
}