Cod sursa(job #3362973)

Utilizator CorvinJudge0Corvin Judge CorvinJudge0 Data 13 august 2026 11:43:10
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.51 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int v[100001];
int a[100001];
struct st{
    int i, v;
} r[100001];
int z[100001];
int cmp(st a, st b){
    return a.v<b.v;
}
void build(int poz, int st, int dr){
    if(st==dr){
        v[poz]=a[st];
       // cout<<poz<<' '<<v[poz]<<'\n';
        return;
    }
    int mij=(dr+st)/2;
    build(poz*2,st,mij);
    build(poz*2+1,mij+1,dr);
    v[poz]=v[2*poz]+v[2*poz+1];
}
void update(int poz, int p, int st, int dr){
    if(!(st<=p&&dr>=p)){
        return;
    }
    if(st==dr){
        v[poz]=a[st];
       // cout<<poz<<' '<<v[poz]<<'\n';
        return;
    }
    int mij=(dr+st)/2;
    update(poz*2,p,st,mij);
    update(poz*2+1,p,mij+1,dr);
    v[poz]=v[2*poz]+v[2*poz+1];
   // cout<<poz<<' '<<v[poz]<<'\n';
}
int cau(int poz, int nr, int st, int dr){
    if(st==dr){
        return st;
    }
    int mij=(st+dr)/2;
    if(v[poz*2]>=nr){
        return cau(poz*2,nr,st,mij);
    }
    return cau(poz*2+1,nr-v[poz*2],mij+1,dr);
}
int main()
{
    ifstream fin("schi.in");
    ofstream fout("schi.out");
    int n, t, p;
    fin>>n;
    for(int i=1;i<=n;i++){
        a[i]=1;
        fin>>z[i];
    }
    reverse(z+1,z+n+1);
    build(1,1,n);
    for(int i=1;i<=n;i++){
        //cout<<v[1]<<' ';
        p=cau(1,z[i],1,n);
      //  cout<<p<<' ';
        a[p]=0;
        r[i].v=p;
        r[i].i=n-i+1;
        update(1,p,1,n);
    }
    //cout<<'\n';
    sort(r+1,r+1+n,cmp);
    for(int i=1;i<=n;i++){
        fout<<r[i].i<<'\n';
    }
    return 0;
}