# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
912489 | 2024-01-19T14:36:42 Z | linvg | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KB |
int[] construct_permutation(int64_t x) { int64_t sum = 1; int64_t mn = 1e9 - 1; vector<int64_t> res; while (sum < x) { int64_t cnt = 0; for (int64_t i = 1; i <= 62; ++i) { if (sum + (1ll << i) - 1 > x) { sum += (1ll << (i-1)) - 1; cnt = i - 1; break; } } // dbg(sum, cnt); for (int64_t i = mn - cnt; i < mn; ++i) { // cout << i << " "; res.pb(i); } mn -= cnt; for (int64_t i = 62; i >= 1; --i) { if (sum + (1ll << (i - 1)) <= x) { sum += (1ll << (i - 1)); cnt = i - 1; res.pb(mn + cnt); } } } // dbg(sum); // dbg(sz(res)); int64_t ans[sz(res)] = {0}; for (int64_t i = 0; i < sz(res); ++i) { ans[i] = res[i]; } return ans; }