#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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |