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>
#include "perm.h"
using namespace std;
using ll = long long;
std::vector<int> construct_permutation(long long k) {
int n = __lg(k);
int ma1,ma2,cur=2;
vector<int> ans(n);
iota(ans.begin(),ans.end(),0);
for(int i=n-1; i>=0;i--){
if((k>>i)&1){
if(cur){
if(cur == 2){
ma2 = i+1;
ans.insert(ans.begin()+i, n);
}
if(cur == 1){
ma1 = i;
ans.insert(ans.begin()+i, n+1);
}
cur--;
}
else if(i-1>=0 && (k>>(i-1))&1 ){
ans[ma1]++; ans[ma2]++;
ans.insert(ans.begin()+i-1, ans[ma2]-1);
ma1++; ma2++;
i--;
}else{
ans.insert(ans.begin()+i, ans[ma1]+1);
ma2 = ma1+1;
ma1 = i;
}
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |