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;
typedef long long ll;
#define pb push_back
vector<int> construct_permutation(ll k){
vector<int> d, ans;
ll tmp = k;
while(tmp){
d.pb(tmp & 3ll);
tmp >>= 2;
}
if(d.back() == 2) ans = {0};
if(d.back() == 3) ans = {1, 0};
d.pop_back();
while(d.size()){
int x = d.back(), n = ans.size(); d.pop_back();
if(x == 0){
ans.pb(n), ans.pb(n + 1);
}else if(x == 1){
ans.pb(n), ans.pb(n + 1), ans.pb(-1);
}else if(x == 2){
ans.pb(n), ans.pb(-1), ans.pb(n + 1);
}else if(x == 3){
bool flag = 0, flag2 = 0;
for(auto x:ans){
flag |= (x == 1);
if(flag && x == 0) flag2 = 1;
}
if(flag2){
ans.pb(n), ans.pb(n + 1);
for(auto &x:ans) x *= 2;
ans.pb(3);
}else{
ans.pb(n), ans.pb(-1), ans.pb(n + 1), ans.pb(-2);
}
}
vector<int> ls = ans;
sort(ls.begin(), ls.end());
for(auto &x:ans) x = lower_bound(ls.begin(), ls.end(), x) - ls.begin();
}
return ans;
}
/*
int main(){
int q; cin >> q;
while(q--){
int k; cin >> k;
vector<int> v = construct_permutation(k);
for(auto x:v) cout << x << ' ';
cout << '\n';
}
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |