# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
912497 | 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)
{
long long sum = 1;
long long mn = 1e9 - 1;
vector<long long> res;
while (sum < x)
{
long long cnt = 0;
for (long long i = 1; i <= 62; ++i)
{
if (sum + (1ll << i) - 1 > x)
{
sum += (1ll << (i - 1)) - 1;
cnt = i - 1;
break;
}
}
// dbg(sum, cnt);
for (long long i = mn - cnt; i < mn; ++i)
{
// cout << i << " ";
res.pb(i);
}
mn -= cnt;
for (long long 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));
return res;
}