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"
using namespace std;
using ll = long long;
vector<int> construct_permutation(long long k) {
ll n = k;
vector<int> ans;
if (n <= 90) {
for (int i=n-2; i>=0; i--) {
ans.push_back(i);
}
return ans;
}
ll main_cap = 0, index = 0;
for (ll i=0; ; i++) {
ll a = (1LL << i);
if (a <= n) {
main_cap = a;
index = i;
}
else {
break;
}
}
for (int i=0; i<=index-1; i++) {
ans.push_back(i);
}
int cur = index;
n -= main_cap;
while (true) {
if (n == 0) {
return ans;
}
vector<int> A;
main_cap = 0, index = 0;
for (ll j=0; ; j++) {
ll a = (1LL << j);
if (a <= n) {
main_cap = a;
index = j;
}
else {
break;
}
}
bool added = false;
index--;
for (auto &e:ans) {
if (e > index) {
if (!added) {
A.push_back(cur);
A.push_back(e);
added = true;
}
else {
A.push_back(e);
}
}
else {
A.push_back(e);
}
}
ans = A;
cur++;
n -= main_cap;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |