This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM "https://judge.yosupo.jp/problem/point_add_range_sum"
#include "../DataStructure/segment_tree.hpp"
#include <iostream>
using lint = long long;
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n, q;
std::cin >> n >> q;
std::vector<lint> xs(n);
for (auto& x : xs) std::cin >> x;
SegmentTree<lint> seg(xs, 0, [](auto a, auto b) { return a + b; });
while (q--) {
int t;
std::cin >> t;
if (t == 0) {
int i;
lint x;
std::cin >> i >> x;
seg.update(i, seg.get(i) + x);
} else {
int l, r;
std::cin >> l >> r;
std::cout << seg.fold(l, r) << "\n";
}
}
return 0;
}#line 1 "Verify/segment_tree_rsq.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/point_add_range_sum"
#line 2 "DataStructure/segment_tree.hpp"
#include <vector>
#include <functional>
template <class T>
struct SegmentTree {
using Merger = std::function<T(T, T)>;
int length;
std::vector<T> dat;
T unit;
Merger merge;
SegmentTree() = default;
SegmentTree(int n, const T& unit, const Merger& merge)
: length(1), unit(unit), merge(merge) {
while (length < n) length <<= 1;
dat.assign(length * 2, unit);
}
template <class Container>
SegmentTree(const Container& elems, const T& unit, const Merger& merge)
: length(1), unit(unit), merge(merge) {
int n = elems.size();
while (length < n) length <<= 1;
dat.assign(length * 2, unit);
std::copy(elems.begin(), elems.end(), dat.begin() + length);
for (int nidx = length - 1; nidx >= 1; --nidx) {
T vl = dat[nidx * 2 + 0];
T vr = dat[nidx * 2 + 1];
dat[nidx] = merge(vl, vr);
}
}
void update(int nidx, const T& elem) {
nidx += length;
dat[nidx] = elem;
while (nidx > 0) {
nidx >>= 1;
T vl = dat[nidx * 2 + 0];
T vr = dat[nidx * 2 + 1];
dat[nidx] = merge(vl, vr);
}
}
T fold(int ql, int qr) const {
ql = std::max(ql, 0);
qr = std::min(qr, length);
ql += length, qr += length;
T lacc = unit, racc = unit;
while (ql < qr) {
if (ql & 1) {
lacc = merge(lacc, dat[ql]);
++ql;
}
if (qr & 1) {
--qr;
racc = merge(dat[qr], racc);
}
ql >>= 1, qr >>= 1;
}
return merge(lacc, racc);
}
T get(int idx) const { return dat[idx + length]; }
T fold_all() const { return dat[1]; }
};
#line 4 "Verify/segment_tree_rsq.test.cpp"
#include <iostream>
using lint = long long;
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n, q;
std::cin >> n >> q;
std::vector<lint> xs(n);
for (auto& x : xs) std::cin >> x;
SegmentTree<lint> seg(xs, 0, [](auto a, auto b) { return a + b; });
while (q--) {
int t;
std::cin >> t;
if (t == 0) {
int i;
lint x;
std::cin >> i >> x;
seg.update(i, seg.get(i) + x);
} else {
int l, r;
std::cin >> l >> r;
std::cout << seg.fold(l, r) << "\n";
}
}
return 0;
}