# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
912496 | linvg | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KiB |
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 "perm.h"
std::vector<int> construct_permutation(long long 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));
int ans[sz(res)] = {0};
for (int64_t i = 0; i < sz(res); ++i)
{
ans[i] = res[i];
}
return ans;
}