/** * @FileName a.cpp * @Author kanpurin * @Created 2021.09.08 18:23:55 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; template< typename Monoid > struct DynamicSegmentTree { private: struct Node; using Func = function; using node_ptr = unique_ptr; Func F; Monoid e; size_t n; struct Node { size_t index; Monoid value,prod; node_ptr left, right; Node(size_t index, Monoid value) : index(index), value(value), prod(value), left(nullptr), right(nullptr) {} }; void node_update(node_ptr &np) const { np->prod = F(F(np->left?np->left->prod:e,np->value), np->right?np->right->prod:e); } void _update(node_ptr& t, size_t a, size_t b, size_t p, Monoid &val) const { if (!t) { t = make_unique(p, val); return; } if (t->index == p) { t->value = val; node_update(t); return; } size_t c = (a+b)/2; if (p < c) { if (t->index < p) swap(t->index,p), swap(t->value,val); _update(t->left,a,c,p,val); } else { if (p < t->index) swap(p,t->index), swap(val,t->value); _update(t->right,c,b,p,val); } node_update(t); } Monoid _get(const node_ptr& t, size_t a, size_t b, size_t l, size_t r) const { if (!t || b <= l || r <= a) return e; if (l <= a && b <= r) return t->prod; size_t c = (a + b) / 2; Monoid result = _get(t->left, a, c, l, r); if (l <= t->index && t->index < r) result = F(result, t->value); return F(result, _get(t->right, c, b, l, r)); } void _print(node_ptr& t) { if (!t) return; cout << "[" << t->index << "] : " << t->value << endl; _print(t->left); _print(t->right); } node_ptr root; public: DynamicSegmentTree(size_t n, const Func f, const Monoid &e) : n(n), F(f), e(e), root(nullptr) {} void update_query(size_t x, Monoid val) { assert(x < n); _update(root, 0, n, x, val); } Monoid get_query(size_t l, size_t r) const { assert(l <= r && r <= n); return _get(root, 0, n, l, r); } Monoid operator[](int x) const { return get_query(x,x+1); } void print() { _print(root); } size_t size() { return n; } }; int main() { int n;scanf("%d",&n); DynamicSegmentTree seg(1000000001,[](ll a,ll b){return a+b;},0); unordered_map mp; ll ans = 0; for (int i = 0; i < n; i++) { int t,x,y;scanf("%d%d%d",&t,&x,&y); if (t == 0) { mp[x] += y; seg.update_query(x,mp[x]); } else { ans += seg.get_query(x,y+1); } } printf("%lld\n",ans); return 0; }