/* -*- coding: utf-8 -*- * * 3205.cc: No.3205 Range Pairwise Xor Query - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_QN = 200000; const int BN = 26; /* typedef */ using ll = long long; /* global variables */ int as[MAX_N], ls[MAX_QN], rs[MAX_QN]; int css[MAX_N + 1]; ll res[MAX_QN]; /* subroutines */ /* main */ int main() { int n, qn; scanf("%d%d", &n, &qn); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < qn; i++) scanf("%d%d", ls + i, rs + i), ls[i]--; for (int k = 0; k < BN; k++) { for (int i = 0; i < n; i++) css[i + 1] = css[i] + ((as[i] >> k) & 1); for (int i = 0; i < qn; i++) { int c1 = css[rs[i]] - css[ls[i]]; int c0 = (rs[i] - ls[i]) - c1; res[i] += (((ll)c0 * c1) << k); } } for (int i = 0; i < qn; i++) printf("%lld\n", res[i]); return 0; }