/* -*- coding: utf-8 -*- * * 1863.cc: No.1863 Xor Sum 2...? - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int BN = 30; /* typedef */ typedef long long ll; struct Vec { int vs[BN]; Vec(): vs() {} Vec operator+(const Vec &w) const { Vec r; for (int i = 0; i < BN; i++) r.vs[i] = vs[i] + w.vs[i]; return r; } Vec operator-(const Vec &w) const { Vec r; for (int i = 0; i < BN; i++) r.vs[i] = vs[i] - w.vs[i]; return r; } }; /* global variables */ int as[MAX_N], bs[MAX_N], bcs[MAX_N + 1], ocs[MAX_N + 1]; Vec avs[MAX_N + 1]; /* subroutines */ bool check(Vec &v0, Vec &v1) { for (int i = 0; i < BN; i++) if (v0.vs[i] + 1 < v1.vs[i]) return false; return true; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < n; i++) scanf("%d", bs + i); for (int i = 0; i < n; i++) { avs[i + 1] = avs[i]; for (int j = 0; j < BN; j++) avs[i + 1].vs[j] += (as[i] >> j) & 1; } for (int i = 0; i < n; i++) { bcs[i + 1] = bcs[i] ^ bs[i]; ocs[i + 1] = ocs[i] + bcs[i + 1]; } ll sum = 0; for (int i = 0; i < n; i++) { int j0 = i, j1 = n + 1; while (j0 + 1 < j1) { int j = (j0 + j1) / 2; if (check(avs[i], avs[j])) j0 = j; else j1 = j; } //printf("i=%d, j0=%d\n", i, j0); int oc = ocs[j0] - ocs[i]; if (! bcs[i]) oc = (j0 - i) - oc; sum += oc; } printf("%lld\n", sum); return 0; }