// Problem: D. Vitya and Strange Lesson
// Contest: Codeforces - Codeforces Round 430 (Div. 2)
// URL: https://codeforces.com/contest/842/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
/*
Author: MikiMiku
*/
#include <bits/stdc++.h>
using namespace std;
/* DEBUGGING */
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 LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
/* CONTAINER SHORTCUT */
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/* GLOBAL OVERWRITE */
//#define int long long
#define endl '\n'
/* BIT MANIPULATION */
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define LSB(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1)) // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S - 1))
#define turnOnLastZero(S) ((S) | (S + 1))
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
/* GEOMETRY */
typedef complex<double> Point;
/* TYPE RE-DEFINE */
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
/* CONSTANT */
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const int FMOD = 998244353;
const ll INF = 1e9;
const ld EPS = 1e-9;
const double PI=acos(-1);
/* SHORTCUT */
#define fi first
#define se second
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef map<int,int> mii;
/* RANDOM */
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
#define SHUF(v) shuffle(all(v), rng);
//FLOAT PRECISION SETTINGS
/*
cout.setf(ios::fixed,ios::floatfield);
cout.precision(3);
*/
//FILE IO
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
//........................................................................
struct node {
int cnt;
node* ch0;
node* ch1;
node() {
cnt = 0;
ch0 = NULL;
ch1 = NULL;
}
};
signed main() {
ios_base::sync_with_stdio(0);cin.tie(nullptr); cout.tie(nullptr);
int n, m;
cin >> n >> m;
set<int> st;
for(int i = 0; i < n; ++i) {
int ai; cin >> ai;
st.insert(ai);
}
vector<int> a(all(st));
const int blim = 19;
node* root = new node();
for(int i = 0; i < sza(a); ++i) {
bitset<blim> bs(a[i]);
node* cur = root;
for(int j = blim-1; j >= 0; --j) {
if(bs[j]) {
if(cur->ch1 == NULL) cur->ch1 = new node();
cur->ch1->cnt++;
cur = cur->ch1;
} else {
if(cur->ch0 == NULL) cur->ch0 = new node();
cur->ch0->cnt++;
cur = cur->ch0;
}
}
}
int xo = 0;
for(int i = 0; i < m; ++i) {
int x; cin >> x;
xo ^= x;
bitset<blim> bs(xo);
node* cur = root;
string res;
for(int j = blim-1; j >= 0; --j) {
//if(cur->ch0 == NULL) cur->ch0 = new node();
//if(cur->ch1 == NULL) cur->ch1 = new node();
//cerr << j << " " << cur->ch0->cnt << " " << cur->ch1->cnt << endl;
if(bs[j]) {
if(cur->ch1 == NULL) cur->ch1 = new node();
if(cur->ch1->cnt == (1<<j)) {
if(cur->ch0 == NULL) cur->ch0 = new node();
cur = cur->ch0;
res += '0';
} else {
cur = cur->ch1;
res += '1';
}
} else {
if(cur->ch0 == NULL) cur->ch0 = new node();
if(cur->ch0->cnt == (1<<j)) {
if(cur->ch1 == NULL) cur->ch1 = new node();
cur = cur->ch1;
res += '1';
} else {
cur = cur->ch0;
res += '0';
}
}
}
bitset<blim> bsx(res); //dbg(bs); dbg(bsx); dbg_out();
bsx ^= bs;
int ans = bsx.to_ulong();
cout << ans << endl;
}
return 0;
}
622. Design Circular Queue | 814. Binary Tree Pruning |
791. Custom Sort String | 787. Cheapest Flights Within K Stops |
779. K-th Symbol in Grammar | 701. Insert into a Binary Search Tree |
429. N-ary Tree Level Order Traversal | 739. Daily Temperatures |
647. Palindromic Substrings | 583. Delete Operation for Two Strings |
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |
445. Add Two Numbers II | 442. Find All Duplicates in an Array |
437. Path Sum III | 436. Find Right Interval |
435. Non-overlapping Intervals | 406. Queue Reconstruction by Height |
380. Insert Delete GetRandom O(1) | 332. Reconstruct Itinerary |
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |