#include #define rep(i,n) for (int i = 0; i < (n); ++i) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define all(x) (x).begin(), (x).end() #define int long long using namespace std; using ll = long long; using P = pair; using VI = vector; using VVI = vector; signed main() { int n, q; cin >> n >> q; VI a(n); rep(i, n) cin >> a[i]; string st; cin >> st; vector> d(30); ll s = 0; vector dif(n); rep(i, n) { int t = 0; rep(k, 30) { if (st[i] == '0' && (a[i] >> k & 1) == 0) { if (d[k].empty()) { t -= 1 << k; } else if (d[k].back().second == 1) { t -= 1 << k; } d[k].emplace_back(i, 0); } else if (st[i] == '1' && (a[i] >> k & 1) == 1) { if (d[k].empty()) { t += 1 << k; } else if (d[k].back().second == 0) { t += 1 << k; } d[k].emplace_back(i, 1); } } s += abs(t); dif[i] = t; } rep(_, q) { int ti; cin >> ti; ll ans = s; map m; rep(k, 30) { if (d[k].empty()) continue; int i = d[k][0].first, c = d[k][0].second; if (c == (ti >> k & 1)) { if (m.find(i) == m.end()) { m[i] = dif[i]; } if (c == 1) m[i] -= 1 << k; else m[i] += 1 << k; } } for(auto p: m) { int i, t; tie(i, t) = p; ans += -abs(dif[i]) + abs(t); } cout << ans << endl; } }