Submission #710581

#TimeUsernameProblemLanguageResultExecution timeMemory
710581AstraytPermutation (APIO22_perm)C++17
100 / 100
8 ms356 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...