# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
912487 | 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 <bits/stdc++.h>
using namespace std;
#define LINVG
#define int long long
#define ii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define endl "\n"
#define fill(x, y) memset(x, y, sizeof(x))
#define heapMax priority_queue<int>
#define heapMin priority_queue<int, vector<int>, greater<int>>
string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef LINVG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
template<class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } return a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> T sqr(T x) { return x * x; }
template<class T> T cube(T x) { return x * x * x; }
const int INF = 0x3f3f3f3f3f;
void solve()
{
int x;
cin >> x;
int sum = 1;
int mn = 1e9 - 1;
vector<int> res;
while (sum < x) {
int cnt = 0;
for (int i = 1; i <= 62; ++i) {
if (sum + (1ll << i) - 1 > x) {
sum += (1ll << (i-1)) - 1;
cnt = i - 1;
break;
}
}
// dbg(sum, cnt);
for (int i = mn - cnt; i < mn; ++i) {
// cout << i << " ";
res.pb(i);
}
mn -= cnt;
for (int 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));
if (sum != x) return void (cout << "-1\n");
if (sz(res) > 200) return void (cout << "-1\n");
cout << sz(res) << endl;
for (auto &c : res) cout << c << " ";
// dbg(sum);
cout << endl;
}
int32_t main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int t;
cin >> t;
while (t--)
solve();
return 0;
}