Cod sursa(job #3329478)

Utilizator OrhanZLTOrhan Zlatkov OrhanZLT Data 13 decembrie 2025 12:39:51
Problema Schi Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second

using namespace std;

const ll MOD=1e9+7;
const string filename="schi";
ifstream fin(filename+".in");
ofstream fout(filename+".out");

int main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(nullptr);
    //fout<<"hi";
    ///*
    ll n,og;
    fin>>og;
    n=og;
    while(n!=(n&(-n)))n+=n&(-n);
    vector<ll> ans(n*2,0),st(og+1,0);
    vector<bool> full(n*2,false);
    for(ll i=1;i<=og;i++){
        fin>>st[i];
    }
    for(ll i=og;i>=1;i--){
        ll pos=st[i]+n-1,x,ch,lc;
        while(full[pos]==true){
            ch=1;
            x=pos;
            lc=1;
            while(x%2==0 && full[x]==true){
                lc=ch;
                x/=2;
                ch*=2;
            }
            pos=pos+lc;
        }
        ans[pos]=i;
        full[pos]=true;
        pos/=2;
        while(pos>0){
            full[pos]=(full[pos*2] && full[pos*2+1]);
            pos/=2;
        }
    }
    for(int i=0;i<og;i++){
        fout<<ans[i+n]<<'\n';
    }
    //*/
    return 0;
}