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(long long k) {
k--;
int len = 0;
for (int i = 60; i > 0; --i) {
if ((1LL << i) - 1 <= k) {
k -= ((1LL << i) - 1);
len = i;
break;
}
}
vector<int> count(len + 1);
for (int i = 60; i >= 0; --i) {
long long vl = (1LL << i);
while (k >= vl) {
count[i]++;
k -= vl;
}
}
vector<int> ans;
int p = 0;
for (int i = len; i > 0; --i) {
p += count[i];
ans.push_back(p);
p++;
}
p = 0;
reverse(ans.begin(), ans.end());
for (int i = len; i >= 0; --i) {
for (int j = 0; j < count[i]; ++j) {
ans.push_back(p);
p++;
}
p++;
}
reverse(ans.begin(), ans.end());
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |