#include #include #include #include #include #include #include #include #include namespace ranges = std::ranges; namespace views = std::views; // #include "Src/Number/IntegerDivision.hpp" // #include "Src/Utility/BinarySearch.hpp" // #include "Src/Sequence/CompressedSequence.hpp" // #include "Src/Sequence/RunLengthEncoding.hpp" // #include "Src/Algebra/Group/AdditiveGroup.hpp" // #include "Src/DataStructure/FenwickTree/FenwickTree.hpp" // #include "Src/DataStructure/SegmentTree/SegmentTree.hpp" // #include "Src/DataStructure/DisjointSetUnion/DisjointSetUnion.hpp" // using namespace zawa; // #include "atcoder/modint" // using mint = atcoder::modint998244353; int N, Q, A[200020]; int main() { std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N >> Q; std::vector cnt(26, std::vector(N)); for (int i = 0 ; i < N ; i++) { std::cin >> A[i]; for (int j = 0, k = A[i] ; j < 26 ; j++, k >>= 1) { cnt[j][i] = k & 1; } } std::vector sum(26, std::vector(N + 1)); for (int i = 0 ; i < 26 ; i++) { for (int j = 0 ; j < N ; j++) sum[i][j + 1] = sum[i][j] + cnt[i][j]; } while (Q--) { int L, R; std::cin >> L >> R; L--; long long ans = 0LL; for (int i = 0 ; i < 26 ; i++) { const int z = sum[i][R] - sum[i][L]; const int o = R - L - z; ans += (1LL << i) * z * o; } std::cout << ans << '\n'; } }