Pagini recente » Cod sursa (job #1759089) | Cod sursa (job #550036) | Cod sursa (job #2605099) | Cod sursa (job #943415) | Cod sursa (job #3184165)
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;
}