Cod sursa(job #2650025)

Utilizator FilipCuciucFilip Cuciuc FilipCuciuc Data 17 septembrie 2020 10:09:54
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.52 kb
//
//  main.cpp
//  C++ - teste
//
//  Created by Filip Cuciuc on 03/02/2020.
//  Copyright © 2020 Filip Cuciuc. vll rights reserved.
//

//#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <map>
#include <string>
#include <cctype>
#include <iomanip>
//#include "MED.h"
using namespace std;
//using namespace std::chrono;

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

const int MAXN = 3e4 + 5;
int n,  v[MAXN], ans[MAXN], tree[4 * MAXN];

void Update (int nod, int st, int dr, int pos, int val){
    if (st == dr){
        tree[nod] = val;
        return;
    }
    int mij = (st + dr) / 2;
    if (pos <= mij){
        Update(nod * 2, st, mij, pos, val);
    }
    else{
        Update(nod * 2 + 1, mij + 1, dr, pos, val);
    }
    tree[nod] = tree[nod * 2] + tree[nod * 2 + 1];
}
 

void read() {
    cin>>n;
   for (int i=1; i<=n; i++){
       Update (1, 1, n, i, 1);
       cin>>v[i];
   }
}

void Querry (int nod, int st, int dr, int pos, int val){
    if (st == dr){
        ans[st] = val;
        Update (1, 1, n, st, 0);
        return;
    }
    int mij = (st + dr) / 2;
    if (tree[nod * 2] >= pos){
        Querry(nod * 2, st, mij, pos, val);
    }
    else{
        Querry(nod * 2 + 1, mij + 1, dr, pos - tree[nod * 2], val);
    }
}

void solve() {
    read();
    for (int i=n; i>=1; i--)
        Querry(1, 1, n, v[i], i);
    
    for (int i=1; i<=n; i++)
        cout<<ans[i]<<'\n';

}
 
int main() {
   
    solve();
    
    return 0;
}