Cod sursa(job #3184165)

Utilizator ililogIlinca ililog Data 14 decembrie 2023 17:27:32
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
using namespace std;
#include<iostream>
#include<fstream>
#include<vector>

#define NMAX 30005

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

int n;
vector<int> loc;
int a[4*NMAX];
int ord[NMAX];

void update(int nod, int st, int dr, int pas, int id) {
    
  //  cout << "(" << nod << ", " << st << ", " << dr << ", " << pas << ", " << id << ")" << endl;
    
    if (st == dr) {
        a[nod] = 1;
        ord[st] = id;
        cout << st << " " << id << endl;
        return;
    }
    
    int mij = (st+dr)/2;
    
    int liber_st = (mij-st+1) - a[nod*2];
    
    if (pas <= liber_st) {
        update(nod*2, st, mij, pas, id);
    } else {
        update(nod*2+1, mij+1, dr, pas - liber_st, id);
    }
    
    a[nod] = a[nod*2] + a[nod*2+1];
}

int main() {
    
    fin >> n;
    for (int i = 1; i<=n; i++) {
        int val;
        fin >> val;
        loc.push_back(val);
    }
    
    while (!loc.empty()) {
        update(1, 1, n, loc[loc.size()-1], loc.size());
        loc.pop_back();
    }
    
    for (int i = 1; i<=n; i++) {
        fout << ord[i] << "\n";
    }
    
    return 0;
}