/* -*- coding: utf-8 -*- * * 2300.cc: No.2300 Substring OR Sum - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int BN = 28; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N]; /* subroutines */ inline int biti(int a, int i) { return (a >> i) & 1; } inline ll sigma(int n) { return (ll)n * (n + 1) / 2; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); ll sum = 0; for (int k = 0; k < BN; k++) { ll s = sigma(n); for (int i = 0; i < n;) { while (i < n && biti(as[i], k)) i++; if (i >= n) break; int j = i; while (i < n && ! biti(as[i], k)) i++; s -= sigma(i - j); } sum += s << k; } printf("%lld\n", sum); return 0; }