Pagini recente » Cod sursa (job #663447) | Cod sursa (job #1362490) | Cod sursa (job #1205732) | Cod sursa (job #802168) | Cod sursa (job #2902094)
#include<bits/stdc++.h>
using namespace std;
ifstream f("order.in");
ofstream g("order.out");
#define cin f
#define cout g
int aInt[120000], copil = 2, pas = 1, n;
void build(int nod, int st, int dr) {
if(st == dr) {
aInt[nod] = 1;
return;
}
int mij = (st + dr) / 2;
build(nod * 2, st, mij);
build(nod * 2 + 1, mij + 1, dr);
aInt[nod] = aInt[nod * 2] + aInt[nod * 2 + 1];
}
void update(int nod, int st, int dr, int copil) {
if(st == dr) {
aInt[nod] = 0;
cout << st << " ";
return;
}
int mij = (st + dr) / 2;
if(copil <= aInt[nod * 2])
update(nod * 2, st, mij, copil);
else {
copil -= aInt[nod * 2];
update(nod * 2 + 1, mij + 1, dr, copil);
}
aInt[nod]--;
}
int main() {
cin >> n;
build(1, 1, n);
while(aInt[1] > 0) {
copil += pas - 1;
while(copil > aInt[1])
copil -= aInt[1];
update(1, 1, n, copil);
pas++;
}
}