Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define F first
- #define S second
- typedef long long ll;
- int n, x;
- bool used[1000005];
- vector < int > ans;
- int main () {
- ios_base::sync_with_stdio(0);
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif // LOCAL
- cin >> n >> x;
- if (n == 2 && x == 0) {
- cout << "NO";
- return 0;
- }
- int f = 0;
- if (n % 4 == 1) {
- ans.push_back(x);
- used[x] = 1;
- f = 1;
- }
- if (n % 4 == 2) {
- ans.push_back(0);
- ans.push_back(x);
- used[x] = 1;
- used[0] = 1;
- f = 1;
- }
- if (n % 4 == 3) {
- for (int i = 0 ; i <= 20 ; i++) {
- if (f)
- break;
- for (int q = i + 1; q <= 20 ; q++) {
- int a = x ^ (1 << i);
- int b = x ^ (1 << q);
- int c = x ^ (1 << i) ^ (1 << q);
- if (a != b && a != c && c != b && a <= 1e6 && b <= 1e6 && c <= 1e6 && !used[a] && !used[b] && !used[c]) {
- ans.push_back(a);
- ans.push_back(b);
- ans.push_back(c);
- used[a] = 1;
- used[b] = 1;
- used[c] = 1;
- f = 1;
- break;
- }
- }
- }
- }
- if (n % 4 == 0) {
- for (int i = 0 ; i <= 20 ; i++) {
- if (f)
- break;
- for (int q = i + 1; q <= 20 ; q++) {
- int a = (1 << i);
- int b = (1 << q);
- int c = a ^ b;
- if (a != b && a != c && c != b && a <= 1e6 && b <= 1e6 && c <= 1e6 && !used[a] && !used[b] && !used[c]) {
- ans.push_back(a);
- ans.push_back(b);
- ans.push_back(c);
- ans.push_back(x);
- used[a] = 1;
- used[b] = 1;
- used[c] = 1;
- used[x] = 1;
- f = 1;
- break;
- }
- }
- }
- }
- int j = 4;
- while (n > 4) {
- if (used[j] | used[j + 1] | used[j + 2] | used[j + 3]) {
- j += 4;
- continue;
- }
- for (int i = 0 ; i < 4 ; i++) {
- used[j + i] = 1;
- ans.push_back(j + i);
- }
- j += 4;
- n -= 4;
- }
- j -= 4;
- if (!f)
- cout << "NO";
- else {
- cout << "YES\n";
- for (int i = 0 ; i < ans.size() ; i++)
- cout << ans[i] << " " ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement