Cod sursa(job #3267412)

Utilizator robert_dumitruDumitru Robert Ionut robert_dumitru Data 11 ianuarie 2025 11:35:15
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <bits/stdc++.h>
using namespace std;

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

/**

8
1 1 3 4 4 2 1 3
7 2 8 6 1 3 5 4
*/

int n;
int aib[30005], a[30005], cls[30005];

void Update(int p, int x)
{
    while (p <= n)
    {
        aib[p] += x;
        p += (p & (-p));
    }
}
int Query(int p)
{
    int suma = 0;
    while (1 <= p)
    {
        suma += aib[p];
        p -= (p & (-p));
    }
    return suma;
}
int CautBin(int val)
{
    int st, dr, mij, P;
    st = 1; dr = n;
    while (st <= dr)
    {
        mij = (st + dr) / 2;
        if (Query(mij) >= val)
        {
            P = mij;
            dr = mij - 1;
        }
        else st = mij + 1;
    }
    Update(P, -1);
    return P;
}

int main()
{
    fin >> n;
    for (int i = 1; i <= n; i++)
    {
        fin >> a[i];
        Update(i, 1);
    }
    for (int i = n; i >= 1; i--)
        cls[CautBin(a[i])] = i;
    for (int i = 1; i <= n; i++)
        fout << cls[i] << "\n";
    return 0;
}