#include "perm.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(time(NULL));
std::vector<int> construct_permutation(long long k)
{
vector<int> ans;
k--;
int n = 0;
vector<pair<int, int> > v;
while(k>0) {
int j = -1;
int mx = 0;
for(int i = 60; i >= 1; --i) {
long long cur = (1ll<<i)-1;
if(cur <= k) {
if(cur == k) {
j = i;
break;
}
int cnt = __builtin_popcountll(k-cur);
if(cnt>mx) {
mx = cnt;
j = i;
}
}
}
int i = j;
n += i;
v.push_back({n-i, n-1});
long long cur = (1ll<<i)-1;
k -= cur;
}
reverse(v.begin(), v.end());
for(auto e : v) {
int l = e.first;
int r = e.second;
for(int i = l; i <= r; ++i) {
ans.push_back(i);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Partially correct |
2 ms |
344 KB |
Partially correct |
4 |
Partially correct |
2 ms |
604 KB |
Partially correct |
5 |
Incorrect |
17 ms |
1884 KB |
Integer 7280 violates the range [1, 5000] |
6 |
Halted |
0 ms |
0 KB |
- |