#include #include using namespace std; using namespace atcoder; typedef long long ll; typedef long double ld; #define sz(c) ((ll)(c).size()) #define ALL(x) x.begin(),x.end() #define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin()) #define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin()) #define BS(A,x) binary_search(ALL(A),x) #define rep(i,a,b) for(int i=a;ibool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } using vi = vector; using vvi = vector; using vl =vector; using vvl=vector; const long long mod=998244353; //using mint = modint998244353; int main() { int n,q;cin>>n>>q; vl A(n); rep(i,0,n)cin>>A[i]; vl ans(q); vl L(q),R(q); rep(i,0,q){cin>>L[i]>>R[i];L[i]--;} rep(i,0,30){ fenwick_treebit(n); rep(j,0,n){ if((A[j]>>i)%2)bit.add(j,1); } rep(j,0,q){ ans[j]+=(1LL<