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 namespace std;
using ll = long long;
const int M = 1'000'000, m = 1'000;
vector<int> solve(ll k){
vector<int> re;
ll b = 0;
while((1ll << b) <= k) k -= (1ll << b), re.push_back(++b + M);
ll r = 0;
for(int i=b-1;i>=0;i--) r += ((!!(k & (1ll << i))) * 1ll) << (b-1-i);
int c = 0, L = 0, L2 = 0;
for(int i=b-1;i>=0;i--, r >>= 1){
if(!(r & 1)) continue;
auto it = re.begin() + (b-i) + c;
if(++c <= 2 || (r & 3) != 3) re.insert(it, M-c*m), L2 = L, L = M-c*m;
else re.insert(it+1, L2+m-c), r ^= 2;
}
return re;
}
vector<int> construct_permutation(ll k)
{
vector<int> ans = solve(--k);
vector<int> v = ans; sort(v.begin(), v.end());
for(auto &x : ans) x = lower_bound(v.begin(), v.end(), x) - v.begin();
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |