#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 |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
264 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |