#include #ifdef DEBUG #include #else #define dump(...) ((void)0) #endif template class DynamicSegmentTree{ using value_type = typename Monoid::value_type; class Node{ public: value_type val; Node *left = nullptr, *right = nullptr; Node(const value_type &val): val(val) {} }; const int64_t size; Node *root = nullptr; std::unordered_map umap; Node* _update(Node *node, int64_t l, int64_t r, int64_t pos, const value_type &val){ int64_t m = (l+r)/2; if(r-l == 1){ if(node) node->val = Monoid::op(node->val, val); else node = new Node(val); umap[pos] = node; }else{ if(!node) node = new Node(val); if(posleft = _update(node->left, l, m, pos, val); else node->right = _update(node->right, m, r, pos, val); node->val = Monoid::op((node->left ? (node->left)->val : Monoid::id()), (node->right ? (node->right)->val : Monoid::id())); } return node; } value_type _query(Node* node, int64_t l, int64_t r, int64_t x, int64_t y){ if(!node) return Monoid::id(); int64_t m = (l+r)/2; if(x <= l && r <= y) return node ? node->val : Monoid::id(); if(r < x || y < l) return Monoid::id(); return Monoid::op(_query(node->left, l, m, x, y), _query(node->right, m, r, x, y)); } public: DynamicSegmentTree(int64_t n): size(pow(2,ceil(log2(n)))){ // [0,n) root = new Node(Monoid::id()); } void update(int64_t i, const value_type &x){ _update(root, 0, size, i, x); } value_type get(int64_t x, int64_t y){ return _query(root, 0, size, x, y); } value_type operator[](int64_t i) const{ if(umap.find(i) != umap.end()) return umap[i]->val; else return Monoid::id(); } }; template struct SumMonoid{ using value_type = T; static value_type ZERO; constexpr inline static value_type id(){return ZERO;} constexpr inline static value_type op(const value_type &a, const value_type &b){return a + b;} }; template struct SumMonoid::value>::type>{ using value_type = T; constexpr inline static value_type id(){return 0;} constexpr inline static value_type op(const value_type &a, const value_type &b){return a + b;} }; int main(){ int n; scanf("%d", &n); DynamicSegmentTree> seg(1000000001); int64_t ans = 0; for(int i = 0; i < n; ++i){ int q,x,y; scanf("%d%d%d", &q, &x, &y); if(q == 0){ seg.update(x,y); }else{ ans += seg.get(x,y+1); } } printf("%lld\n", ans); return 0; }