이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |