Cod sursa(job #2836972)

Utilizator LuxinMatMatasaru Luxin Gabriel LuxinMat Data 21 ianuarie 2022 12:35:14
Problema Schi Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include<fstream>
using namespace std;

ifstream cin("schi.in");
ofstream cout("schi.out");

int n, aib[30001], v[30001], rez[30001];

void update(int pos, int val)
{
    for(int i=pos; i<=n; i += (i&(-i)))
        aib[i] += val;
}

int query(int pos)
{
    int sum = 0;
    for(int i=pos; i>0; i -= (i&(-i)))
        sum += aib[i];
    return sum;
}

int cb(int x)
{
    int pos = 0;
    int pas = 1<<17;
    int nr = query(x);
    while(pas)
    {
        if(pos + pas <= n)
        {
            if(pos + pas < x || query(pos+pas) - nr <= 1)
                pos += pas;
        }
        pas >>= 1;
    }
    return pos;
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>v[i];
    }
    for(int i=n; i>0; i--)
    {
        int curent = query(v[i]);
        int pos = v[i] + curent;
        int next = query(pos);
        while(curent < next)
        {
            curent = next;
            pos = v[i] + curent;
            next = query(pos);
        }
        rez[pos]=i;
        update(pos, 1);
    }
    for(int i=1; i<=n; i++)
        cout<<rez[i]<<'\n';
    return 0;
}