Cod sursa(job #2909927)

Utilizator vlad2009Vlad Tutunaru vlad2009 Data 16 iunie 2022 22:18:59
Problema Order Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <set>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

oset<int> s;

int main() {
    ifstream fin("order.in");
    ofstream fout("order.out");
    int n;
    fin >> n;
    for (int i = 1; i <= n; i++) {
        s.insert(i);
    }
    int index = -1;
    while (n > 0) {
        if (index == -1) {
            index = 1;
        } else {
            index = (2 * index) % n;
        }
        auto it = s.find_by_order(index);
        fout << (*it) << " ";
        s.erase(it);
        n--;
    }
    return 0;
}