Pagini recente » Borderou de evaluare (job #3364509) | Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #3364700)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T, typename Cmp = less<T>>
using ordered_set = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;
signed main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
freopen("order.in", "r", stdin);
freopen("order.out", "w", stdout);
#endif
int n; cin >> n;
ordered_set<int> s;
for (int i = 0; i < n; ++i) { s.insert(i); }
int curr = 0, i = 1;
vector<int> ans;
while (!s.empty()) {
int poz_elim = (curr + i) % n;
auto it = s.find_by_order(poz_elim);
cout << *it + 1 << ' ';
ans.push_back(*it + 1);
s.erase(it);
--n;
if (poz_elim == 0) {
curr = n - 1;
} else {
curr = poz_elim - 1;
}
++i;
}
cout << '\n';
return 0;
}