codeforces
1174D - Ehab and the Expected XOR Problem
That Italy
allows you to construct a number of column A so that he or any other sub-segment value can not be exclusive nor is x 0
at the same time making him the longest
Here we consider a number of columns configured priority prefix A XOR B and the number of columns
then A [i] = B [i ] ^ B [i - 1];
We first consider if you want to as long as possible while 0 and x does not appear as if
we construct the number of column B when it is best to select only i ^ x and i only one that ensures that we do not appear when XOR x
Since we can only half of the data is selected from this last exclusive or so inside the longest l 2 ^ (n-1)
Because there are different B adjacent to each so naturally will not appear 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio ios::sync_with_stdio(false);cin.tie(0)
const int maxn = 2e5 + 5;
int n, x;
bool vis[1 << 18];
signed main() {
fastio;
cin >> n >> x;
int pre = 0;
vector<int> ans;
vis[x] = 1; // x 不能出现
ans.push_back(0);
for(int i = 1; i < (1 << n); i ++) {
if(vis[i])
continue;
vis[i] = vis[i ^ x] = 1; // 优先选取 成对出现的一个
ans.push_back(i); // 现在构成 a的前缀异或和数组
} // 那样 a[i] = b[i + 1] ^ b[i];
cout << ans.size() - 1 << endl;
for(int i = 1; i < ans.size(); i ++) {
cout << (ans[i] ^ ans[i - 1]) << " ";
}cout << endl;
return 0;
}