#include using namespace std; using ll = long long; using pll = pair; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; void solve(){ int n, q; cin >> n >> q; vector a(n+1); for(int i = 1; i <= n; i++) cin >> a[i]; vector> cnt0(n+1, vector(26, 0)), cnt1(n+1, vector(26, 0)); for(int i=1; i<=n; i++){ for(int j=0; j<26; j++){ cnt0[i][j] = cnt0[i-1][j]; cnt1[i][j] = cnt1[i-1][j]; if((a[i]>>j) & 1){ cnt1[i][j]++; } else { cnt0[i][j]++; } } } while(q--){ int l, r; cin >> l >> r; ll ans = 0; for(int j=0; j<26; j++){ ll c0 = cnt0[r][j] - cnt0[l-1][j]; ll c1 = cnt1[r][j] - cnt1[l-1][j]; ans += (c0 * c1) << j; } cout << ans << '\n'; } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }