This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM "https://judge.yosupo.jp/problem/static_range_sum"
#include "../../../src/template/template.hpp"
#include "../../../src/data_structure/disjoint_sparse_table.hpp"
ll op(ll x, ll y) {
return x + y;
}
ll e() {
return 0;
}
int main(void) {
int n, q;
cin >> n >> q;
vector<ll> a(n);
rep(i, 0, n) {
cin >> a[i];
}
DisjointSparseTable<ll, op, e> dst(a);
while(q--) {
int l, r;
cin >> l >> r;
cout << dst.prod(l, r) << '\n';
}
}
#line 1 "verify/library_checker/data_structure/static_range_sum.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/static_range_sum"
#line 2 "src/template/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
#define rep(i, a, b) for(long long i = (a); i < (b); ++i)
#define rrep(i, a, b) for(long long i = (a); i >= (b); --i)
constexpr long long inf = 4e18;
struct SetupIO {
SetupIO() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(30);
}
} setup_io;
#line 3 "src/data_structure/disjoint_sparse_table.hpp"
template <typename S, auto op, auto e>
struct DisjointSparseTable {
DisjointSparseTable(const vector<S>& v)
: n((int)v.size() + 2) {
const int b = 32 - __builtin_clz(n - 1);
table.assign(b, vector<S>(n, e()));
for(int k = 1; k < b; ++k) {
const int w = (1 << k);
for(int i = w; i < n; i += w * 2) {
for(int j = i - 1; j > i - w; --j) {
table[k][j - 1] = op(table[k][j], v[j - 1]);
}
const int m = min(i + w - 1, n - 1);
for(int j = i; j < m; ++j) {
table[k][j + 1] = op(table[k][j], v[j - 1]);
}
}
}
}
S prod(const int l, int r) const {
assert(0 <= l and l <= r and r <= n);
++r;
const auto& s = table[31 - __builtin_clz(l xor r)];
return op(s[l], s[r]);
}
private:
int n;
vector<vector<S>> table;
};
#line 4 "verify/library_checker/data_structure/static_range_sum.test.cpp"
ll op(ll x, ll y) {
return x + y;
}
ll e() {
return 0;
}
int main(void) {
int n, q;
cin >> n >> q;
vector<ll> a(n);
rep(i, 0, n) {
cin >> a[i];
}
DisjointSparseTable<ll, op, e> dst(a);
while(q--) {
int l, r;
cin >> l >> r;
cout << dst.prod(l, r) << '\n';
}
}