Cod sursa(job #2776738)

Utilizator raulandreipopRaul-Andrei Pop raulandreipop Data 20 septembrie 2021 21:39:44
Problema Schi Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

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

long int n;
long long bit[30069];
int poz[30030];

void update (int i, int val)
{
    while (i <= n)
    {
        bit[i] += val;
        i += (i & -i);
    }
}
long long ps(int i)
{
    long long sum = 0;
    while (i > 0)
    {
        sum += bit[i];
        i -= (i & -i);
    }
    return sum;
}
int rangeSum(int i, int j){
    return ps(j) - ps(i - 1);
}
long long ans[30030];
long long fin[30030];

int main ()
{
    in >> n;
    for (int i = 1; i <= n; i++)
    {
        in >> poz[i];
    }
    for (int i = n; i > 0; i --)
    {
        fin[i] = poz[i] + ps(poz[i]);
        
        update(poz[i], 1);
    }
    int k;
    for (int i = n; i > 0; i--)
    {
        int incr = 0;
        while (ans[fin[i] + incr])
            incr ++;
        ans[fin[i] + incr] = i;
    }
    for (int i = 1; i <= n; i ++)
    {
        out << ans[i] << "\n";
    }
}