# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
582682 | Vanilla | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<int>
construct_permutation(ll k)
{
--k;
int m = 1;
while(k+1 > (1ll<<(m))) {
++m;
}
vector<int> perm(m);
for (int i = 0; i < m; ++i) {
perm[i] = i;
}
for (int i = m-2; i >= 0; --i) {
if ((k & (1ll << i)) == 0)
swap(perm[i],perm[i+1]);
}
return perm;
}