#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using Vi = vector; using VVi = vector; using Vl = vector; using VVl = vector; using P = pair; using Vp = vector

; using VVp = vector; using Pl = pair; using Vpl = vector; using VVpl = vector; using tup = tuple; using Vt = vector>; using Pll = pair; using Vc = vector; using VVc = vector; template using PQmax = priority_queue; template using PQmin = priority_queue, greater>; void tprsort(int u, const VVi& gr, Vi& tpr, Vi& par); void tprsort(const VVi& gr, Vi& tpr); ll mpow(ll x, ll n, ll m = 1e9 + 7); ll comb(int n, int r, const Vl& kai, const Vl& fkai, ll m = 1e9 + 7); ll gcd(ll a, ll b); int LCA(const VVi& par, const Vi& depth, int a, int b); Vi sccResolve(const VVi& gr); void dijkstra(const VVi& gr, const VVl& cost, Vl& dist, int s); class unionfind { private: Vi par; Vi siz; Vi val; public: unionfind(int N); unionfind(); int root(int v); void merge(int a, int b); bool same(int a, int b); int value(int a); }; int main() { int N; cin >> N; Vl A(N), B(N + 1); Vl sum(N + 1); Vl xoa(N + 1); Vl cnt(N + 1); sum[0] = xoa[0] = cnt[0] = 0; for (int i = 0; i < N; i++) { cin >> A[i]; /*if (i) { B[i] = B[i] ^ B[i - 1]; } sum[i + 1] = sum[i] + A[i]; xoa[i + 1] = xoa[i] ^ A[i]; cnt[i + 1] = cnt[i] + B[i];*/ } B[0] = 0; for (int i = 0; i < N; i++) { cin >> B[i + 1]; B[i + 1] ^= B[i]; cnt[i + 1] = cnt[i] + B[i + 1]; } /*for (int i = 0; i < N; i++) { cout << B[i] << ' '; } cout << endl; for (int i = 0; i <= N; i++) { cout << cnt[i] << ' '; } cout << endl;*/ ll ans = 0; int r = 0; ll s = 0; ll x = 0; for (int l = 0; l < N; l++) { if (l == r) { r++; s += A[r - 1]; x = x ^ A[r - 1]; } while (r <= N) { r++; if (r > N) { r--; break; } s += A[r - 1]; x = x ^ A[r - 1]; if (s > x) { r--; s -= A[r]; x ^= A[r]; break; } } if (!B[l]) { ans += (r - l) - (cnt[r] - cnt[l]); } else { ans += (cnt[r] - cnt[l]); } s -= A[l]; x ^= A[l]; // cout << l << ' ' << r << ' ' << ans << endl; } cout << ans << endl; } // Library void tprsort(const VVi& gr, Vi& tpr) { queue que; int N = gr.size(); Vi siz(N, 0); for (int i = 0; i < N; i++) { for (int j : gr[i]) { siz[j]++; } } for (int i = 0; i < N; i++) { if (siz[i] == 0) { que.push(i); } } while (!que.empty()) { int u = que.front(); que.pop(); tpr.push_back(u); for (int v : gr[u]) { siz[v]--; if (siz[v] == 0) { que.push(v); } } } reverse(tpr.begin(), tpr.end()); } void tprsort(int u, const VVi& gr, Vi& tpr, Vi& par) { // idx[u] = tpr.size(); /*for (int v : gr[u]) { if (par[v] == u || par[v] == -1) { par[v] = u; tprsort(v, gr, tpr, par); } } tpr.push_back(u);*/ stack st; st.push(u); bool vis[2000020]; for (int i = 0; i <= gr.size(); i++) { vis[i] = false; } while (!st.empty()) { int v = st.top(); if (!vis[v]) { vis[v] = true; for (int p : gr[v]) { if (par[p] == -1) { par[p] = v; st.push(p); } } } else { tpr.push_back(v); st.pop(); } } } Vi sccResolve(const VVi& gr) { int N = gr.size(); Vi tpr; Vi par(N, -1); for (int i = 0; i < N; i++) { if (par[i] == -1) { tprsort(i, gr, tpr, par); } } Vi ret(N, -1); int now = 0; for (int i = N - 1; i >= 0; i--) { int u = tpr[i]; if (ret[u] != -1) { continue; } ret[u] = now; stack st; st.push(u); while (!st.empty()) { int v = st.top(); st.pop(); for (int p : gr[v]) { if (ret[p] == -1) { st.push(p); ret[p] = now; } } } now++; } return ret; } ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; } ll mpow(ll x, ll n, ll m) { ll ret = 1; while (n) { if (n % 2) { ret *= x; ret %= m; } x = (x * x) % m; n /= 2; } return ret; } ll comb(int n, int r, const Vl& kai, const Vl& fkai, ll m) { if (n < 0 || r < 0 || n < r) { return 0; } ll ret = kai[n]; ret *= fkai[r]; ret %= m; ret *= fkai[n - r]; ret %= m; return ret; } int LCA(const VVi& par, const Vi& depth, int a, int b) { if (depth[a] < depth[b]) { swap(a, b); } int dis = depth[a] - depth[b]; for (int i = 19; i >= 0; i--) { if ((dis >> i) & 1) { a = par[i][a]; } } if (a == b) { return a; } for (int i = 19; i >= 0; i--) { if (par[i][a] != par[i][b]) { a = par[i][a]; b = par[i][b]; } } return par[0][a]; } void dijkstra(const VVi& gr, const VVl& cost, Vl& dist, int s) { ll INF = (ll)1e18; dist.assign(gr.size(), INF); dist[s] = 0; PQmin pque; pque.push(make_pair(0, s)); while (!pque.empty()) { auto [L, u] = pque.top(); pque.pop(); while (L != dist[u] && !pque.empty()) { tie(L, u) = pque.top(); pque.pop(); } for (int i = 0; i < gr[u].size(); i++) { int v = gr[u][i]; ll c = cost[u][i]; if (dist[v] > c + L) { dist[v] = c + L; pque.push(make_pair(dist[v], v)); } } } return; } unionfind::unionfind(int N) { par.resize(N + 1); siz.assign(N + 1, 1); val.assign(N + 1, 0); for (int i = 0; i <= N; i++) { par[i] = i; } } unionfind::unionfind() { par.resize(100010); siz.assign(100010, 1); val.assign(100010, 0); for (int i = 0; i <= 100010; i++) { par[i] = i; } } int unionfind::root(int v) { if (v == par[v]) { return v; } return par[v] = root(par[v]); } void unionfind::merge(int a, int b) { a = root(a); b = root(b); if (a == b) { return; } if (siz[a] < siz[b]) { int t = a; a = b; b = t; } par[b] = a; siz[a] += siz[b]; /* ここにvalについての演算処理を書く */ } bool unionfind::same(int a, int b) { a = root(a); b = root(b); return a == b; } int unionfind::value(int a) { return siz[this->root(a)]; }