from atcoder.segtree import SegTree N,Q = map(int,input().split()) A = map(int,input().split()) X = [[0] * N for _ in range(26)] for i,a in enumerate(A): for j in range(26): X[j][i] = a & 1 a >>= 1 X = [SegTree(lambda x,y:x+y, 0, X[i]) for i in range(26)] for _ in range(Q): L,R = map(int,input().split()) ans = 0 for i in range(26): x = X[i].prod(L-1,R) ans += ((R-L+1-x) * x) * (1<