제출 #579955

#제출 시각아이디문제언어결과실행 시간메모리
579955JooDdae순열 (APIO22_perm)C++17
100 / 100
2 ms340 KiB
#include "perm.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const int M = 1'000'000, m = 1'000; vector<int> solve(ll k){ vector<int> re; ll b = 0; while((1ll << b) <= k) k -= (1ll << b), re.push_back(++b + M); ll r = 0; for(int i=b-1;i>=0;i--) r += ((!!(k & (1ll << i))) * 1ll) << (b-1-i); int c = 0, L = 0, L2 = 0; for(int i=b-1;i>=0;i--, r >>= 1){ if(!(r & 1)) continue; auto it = re.begin() + (b-i) + c; if(++c <= 2 || (r & 3) != 3) re.insert(it, M-c*m), L2 = L, L = M-c*m; else re.insert(it+1, L2+m-c), r ^= 2; } return re; } vector<int> construct_permutation(ll k) { vector<int> ans = solve(--k); vector<int> v = ans; sort(v.begin(), v.end()); for(auto &x : ans) x = lower_bound(v.begin(), v.end(), x) - v.begin(); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...