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;
#define ll long long
int mx, cnt;
ll p[62];
vector<int> res, l;
std::vector<int> construct_permutation(long long k)
{
p[0]=1;
for (int i=1; i<62; i++) p[i]=p[i-1]*2;
if (k==1) return vector<int> {};
mx=cnt=0;
res.clear();
l.clear();
ll tmp=k;
while (tmp>0)
{
if (tmp%2==1) mx=max(mx, cnt);
tmp/=2;
cnt++;
}
ll vl=k-p[mx];
for (int i=0; i<mx; i++) res.push_back(i);
if (vl==0) return res;
vl--;
cnt=0;
while (vl>0)
{
if (vl%2==1) l.push_back(cnt);
vl/=2;
cnt++;
}
for (auto x:l) res[x]--;
for (int i=0; i<mx; i++) res[i]++;
res.push_back(l.size());
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |