#pragma GCC optimize("O3") #include #define debug(...) ((void)0) #include template struct sparse_segtree { static_assert(std::is_convertible_v>, "op must work as S(S, S)"); static_assert(std::is_convertible_v>, "e must work as S()"); static_assert(std::is_unsigned_v, "Size must be a signed integral type"); sparse_segtree() : root(new node(nullptr)) {} void set(const Size p, const S x) { assert(p < max_size); root->set(p, x); } S get(const Size p) const { assert(p < max_size); return root->get(p); } S prod(const Size l, const Size r) const { assert(l <= r); assert(r < max_size); if (l == r) { return e(); } return root->prod(l, r); } private: static constexpr Size max_size = (Size(1) << Size(std::numeric_limits::digits - 1)); struct node { node *parent, *left, *right; S val; explicit node(node* p) : parent(p), val(e()){}; void set(const Size p, const S x, const Size cur_l = 0, const Size cur_r = max_size) { if (cur_l + 1 == cur_r) { val = x; update(); return; } const Size cur_mid = std::midpoint(cur_l, cur_r); // left if (p < cur_mid) { if (!left) left = new node(this); left->set(p, x, cur_l, cur_mid); return; } // right if (!right) right = new node(this); right->set(p, x, cur_mid, cur_r); } S get(const Size p, const Size cur_l = 0, const Size cur_r = max_size) const { if (cur_l + 1 == cur_r) return val; const Size cur_mid = std::midpoint(cur_l, cur_r); // left if (p < cur_mid) { return left ? left->get(p, cur_l, cur_mid) : e(); } // right return right ? right->get(p, cur_mid, cur_r) : e(); } S prod(const Size l, const Size r, const Size cur_l = 0, const Size cur_r = max_size) const { if (l <= cur_l && cur_r <= r) return val; const Size cur_mid = std::midpoint(cur_l, cur_r); if (r <= cur_mid) { return left ? left->prod(l, r, cur_l, cur_mid) : e(); } if (cur_mid <= l) { return right ? right->prod(l, r, cur_mid, cur_r) : e(); } return op(left ? left->prod(l, r, cur_l, cur_mid) : e(), right ? right->prod(l, r, cur_mid, cur_r) : e()); } void update() { // if not a leaf, update val if (left || right) { val = e(); if (left) val = op(val, left->val); if (right) val = op(val, right->val); } if (parent) parent->update(); } }; node* root; }; using namespace std; using ll = long long; using ld = long double; using S = ll; S op(S a, S b) { return a + b; } S e() { return 0; } using segtree = sparse_segtree; void solve(int) { int q; cin >> q; segtree st; ll ans = 0; for (int i = 0; i < q; i++) { int t; cin >> t; if (t == 0) { ll x, y; cin >> x >> y; st.set(x, st.get(x) + y); continue; } if (t == 1) { ll l, r; cin >> l >> r; ans += st.prod(l, r + 1); continue; } } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(0); }