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>
#include "perm.h"
typedef long long ll;
using namespace std;
void add1(vector<int>& ans) {
for (auto& i : ans) {
i++;
}
ans.push_back(0);
}
void add3(vector<int>& ans) {
ans.insert(ans.begin() + 2, ans.size());
}
void mul2(vector<int>& ans) {
ans.push_back(ans.size());
}
std::vector<int> construct_permutation(long long k)
{
if (k <= 90) {
vector<int> all;
for (ll i = 0; i < k - 1; i++) {
all.push_back(i);
}
reverse(all.begin(), all.end());
return all;
}
vector<ll> all;
while (k) {
all.push_back(k & 1);
k /= 2;
}
vector<int> ans;
ans.push_back(1);
ans.push_back(0);
all.pop_back();
ll lst = all.back();
all.pop_back();
if (!lst) {
lst = all.back();
all.pop_back();
add1(ans);
if (lst) {
add1(ans);
}
}
while (!all.empty()) {
lst = all.back();
all.pop_back();
mul2(ans);
if (lst) {
if (!all.empty() && all.back()) {
all.pop_back();
mul2(ans);
add3(ans);
} else {
add1(ans);
}
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |