#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll inf = 1e18;
mt19937 rnd(234);
const ll mod = 1e9 + 7;
typedef complex<flt> base;
const flt pi = atan2(1, 0) * 2;
const int maxn = 1e6;
int n, q;
int a[maxn];
int b[maxn * 2];
int rs[maxn + 10];
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n >> q;
for (int i = 0; i < n; i += 1) {
cin >> a[i];
}
for (int i = 0; i < n; i += 1) {
cin >> b[i];
}
for (int i = 0; i <= q; i += 1) {
rs[i] = 0;
}
vector<int> sa(n);
for (int i = 0; i < n; i += 1) {
sa[i] = i;
}
sort(all(sa), [&](int i, int j) {return a[i] > a[j];});
int last = 0;
int b_can_do = 4e8 / n;
int b_border = max(0.0, 1e9 - (1e9 / (n + q) * b_can_do));
int super_can_do = 4e8 / 1e4;
int super_border = max(0.0, 1e9 - (1e9 / (n + q) * super_can_do));
auto update = [&](int j) {
int l = max(0, j - q);
int r = min(j, n - 1);
int pos = b[j] / (1e9 / (n + q));
assert(0 <= pos and pos < n + q);
int aboba = (flt)(200) * (n + q) / (n + q - pos);
aboba = max(aboba, 200);
aboba = min(aboba, n - 1);
for (int x = 0; x <= aboba; x += 1) {
int k = sa[x];
if (l <= k and k <= r) {
rs[j - k] = max(rs[j - k], a[k] + b[j]);
}
}
};
for (int j = 0; j < n; j += 1) {
update(j);
}
for (int i = 0; i <= q; i += 1) {
last = rs[i];
cout << last << "\n";
if (i < q) {
int j = n + i;
cin >> b[j];
b[j] ^= last;
update(j);
}
}
return 0;
}