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 <iostream>
#include <vector>
using namespace std;
vector<int> construct_permutation(long long k){
vector<int> a;
while((1ll<<a.size()) <= k) a.push_back(a.size());
a.pop_back();
k -= 1<<a.size();
if(k > 0){
int bt = 60;
while(!((k >> bt)&1)) --bt;
for(int &x:a) if(x >= bt) ++ x;
a.push_back(bt);
k -= 1LL<<bt --;
while(bt >= 0){
if(bt > 0 && (k>>(bt-1)) == 3){
--bt;
for(int &x:a) if(x >= bt) ++ x;
a.insert(a.end() - 2, bt);
k -= 3LL<<bt--;
}
else if((k >> bt) == 1){
for(int &x:a) if(x >= bt) ++x;
a.push_back(bt);
k -= 1LL<<bt--;
}
else bt --;
}
}
return a;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |