#include #ifdef DEBUG #include #else #define dump(...) ((void)0) #endif template class DynamicSegmentTree{ using value_type = typename Monoid::value_type; struct Node{ value_type val; Node *left = nullptr, *right = nullptr; Node(const value_type &val): val(val) {} }; const int64_t size; Node *root = nullptr; Node* update_aux(Node *node, int64_t l, int64_t r, int64_t pos, const value_type &val){ if(r-l == 1){ if(node) node->val = Monoid::op(node->val, val); else node = new Node(val); }else{ int64_t m = (l+r)/2; if(!node) node = new Node(val); if(pos < m) node->left = update_aux(node->left, l, m, pos, val); else node->right = update_aux(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 get_aux(Node* node, int64_t l, int64_t r, int64_t x, int64_t y) const { if(!node) return Monoid::id(); if(x <= l && r <= y) return node ? node->val : Monoid::id(); if(r < x || y < l) return Monoid::id(); int64_t m = (l + r) >> 1; return Monoid::op(get_aux(node->left, l, m, x, y), get_aux(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_aux(root, 0, size, i, x); } value_type get(int64_t l, int64_t r) const { return get_aux(root, 0, size, l, r); } value_type operator[](int64_t i) const { return get(i, i+1); } }; 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; }