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 "perm.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> construct_permutation(long long k) {
int b = 63 - __builtin_clzll(k);
k -= 1LL << b;
vector<int> key(b);
iota(key.begin(), key.end(), 0);
int cnt = 0;
while (k > 0) {
b = 63 - __builtin_clzll(k);
if (cnt >= 1 && b > 0 && ((k >> (b - 1)) & 1)) {
b--;
for (int &v : key) {
if (v >= b) v++;
}
key.insert(key.end() - 2, b);
k -= 3LL << b;
} else {
for (int &v : key) {
if (v >= b) v++;
}
key.push_back(b);
k -= 1LL << b;
cnt++;
}
}
return key;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |