Submission #1199424

#TimeUsernameProblemLanguageResultExecution timeMemory
1199424sula2Permutation (APIO22_perm)C++20
91.33 / 100
2 ms328 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define bitcount __builtin_popcount
#define all(a) a.begin(), a.end()
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update>;

vector<int> construct_permutation(long long k) {
    vector<long long> path;
    while (k > 0) {
        path.push_back(k);
        k = k & 1 ? k - 1 : k / 2;
    }
    reverse(all(path));
    vector<int> seq;
    int mn = 0, mx = 1;
    for (int i = 1; i < path.size(); i++) {
        if (path[i] == path[i-1] + 1)
            seq.push_back(mn--);
        else
            seq.push_back(mx++);
    }
    mn++;
    for (int& x : seq) x -= mn;
    return seq;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...