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 lint = long long;
using namespace std;
vector<int> normalise(vector<int> x, int n_pos) {
int diff = x.size() - n_pos - 1;
for (int& y : x) y += diff;
return x;
}
vector<int> construct_permutation(lint k) {
int max_bit = 0;
for (int i = 0; i <= 60; i++)
if (k & (lint) powl(2, i)) max_bit = i;
assert(max_bit != 0);
vector<int> ans;
for (int i = 1; i <= max_bit; i++) ans.push_back(i);
int prev = 1;
for (int bit = 0; bit <= 60; bit++) {
if (!(k & (lint) powl(2, bit))) continue;
if (bit == max_bit) continue;
prev--;
int diff = max_bit - bit;
for (auto it = ans.begin(); it != ans.end(); it++) {
if (*it != diff) continue;
ans.insert(next(it, 1), prev);
break;
}
}
// for (int x : ans) cout << x << " ";
ans = normalise(ans, max_bit);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |