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"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int inf = 1e9;
ll C(ll a, ll b) {
return (a + b - 1) / b;
}
vector<int> construct_permutation(ll k) {
if (k <= 90) {
vector<int> ret(k - 1);
for (int i = 0; i < k - 1; i++) ret[i] = k - 2 - i;
return ret;
}
int n = 120;
vector<int> ret(n);
for (int i = 0; i < n; i++) ret[i] = n - 1 - i;
k -= n + 1;
ll prv = n;
for (int i = n - 1; i >= 0 && k; i--) {
ll e = n - i; ll j = i;
smin(j, C(k, 1ll << (e - 1)));
if (k % (1ll << e) == 0 && j % 2 != 0) j -= 1;
if (k % (1ll << e) != 0 && j % 2 == 0) j -= 1;
if ((j + prv) % 2 == 0) smin(j, prv - 2);
else smin(j, prv - 1);
prv = j;
for (int p = n - 1; p > n - 1 - j; p--) swap(ret[p], ret[p - 1]);
k -= (1ll << (e - 1)) * j;
}
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |