# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
722116 | yeyso | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
using namespace std;
#include "perm.h"
#define int long long;
vector<int> construct_permutation(long long k)
{
k -= 1;
int x = 1;
vector<int> sub = {0};
vector<int> res;
while(sub[sub.size()-1] < k * 2){
sub.push_back(pow(2, x)-1);
x += 1;
}
while(k > 0){
for(int i = 0; i < sub.size(); i ++){
if(sub[i] > k){
k -= sub[i-1];
res.push_back(i-1);
break;
}
}
}
vector<vector<int>> inc;
int res0;
for(int i = 0; i < res.size(); i ++){
inc.push_back({});
for(int j = 0; j < res[i]; j ++){
inc[i].push_back(j+res0);
}
res0 += res[i];
}
vector<int> res2;
reverse(inc.begin(), inc.end());
for(int i = 0; i < inc.size(); i ++){
for(int j = 0; j < inc[i].size(); j ++){
res2.push_back(inc[i][j]);
}
}
return res2;
}