#line 2 "template.hpp" #include using namespace std; #define rep(i, N) for(int i=0;i<(N);i++) #define all(x) (x).begin(),(x).end() #define popcount(x) __builtin_popcount(x) using i128=__int128_t; using ll = long long; using ld = long double; using graph = vector>; using P = pair; constexpr int inf = 1e9; constexpr ll infl = 1e18; constexpr ld eps = 1e-6; const long double pi = acos(-1); constexpr uint64_t MOD = 1e9 + 7; constexpr uint64_t MOD2 = 998244353; constexpr int dx[] = { 1,0,-1,0 }; constexpr int dy[] = { 0,1,0,-1 }; templateinline void chmax(T&x,T y){if(xinline void chmin(T&x,T y){if(x>y)x=y;} #line 1 "data-structure/dynamic_segtree.hpp" /// @brief Dynamic Segment Tree(動的セグメント木) /// @tparam S 要素の型 /// @tparam op 二項演算 /// @tparam e 単位元 /// @docs docs/data-structure/dynamic_segtree.md template class dynamic_segtree { public: dynamic_segtree(const size_t& n) :n(n), root(nullptr) {} private: struct node { S val; node* left; node* right; node(const S& v) :val(v), left(nullptr), right(nullptr) {} }; node* root; size_t n; public: void update(const size_t& p, const S& x) { assert(0 <= p && p < n); internal_update(root, 0, n, p, x); } void add(const size_t& p, const S& x) { assert(0 <= p && p < n); internal_add(root, 0, n, p, x); } S operator[](const size_t& p) { assert(0 <= p && p < n); return internal_access(root, 0, n, p); } S prod(const size_t& l, const size_t& r) { assert(0 <= l && l <= r && r <= n); if (l == r) { return e(); } if (l == 0 && r == n) { return root->val; } return internal_prod(root, 0, n, l, r); } private: void internal_update(node*& p, const size_t& l, const size_t& r, const size_t& idx, const S& new_val) { if (p == nullptr) { p = new node(e()); } if (r - l == 1) { p->val = new_val; return; } size_t mid = (l + r) >> 1; if (idx < mid) internal_update(p->left, l, mid, idx, new_val); else internal_update(p->right, mid, r, idx, new_val); p->val = e(); if (p->left != nullptr) p->val = op(p->left->val, p->val); if (p->right != nullptr) p->val = op(p->val, p->right->val); } void internal_add(node*& p, const size_t& l, const size_t& r, const size_t& idx, const S& new_val) { if (p == nullptr) { p = new node(e()); } if (r - l == 1) { p->val = op(p->val, new_val);; return; } size_t mid = (l + r) >> 1; if (idx < mid) internal_add(p->left, l, mid, idx, new_val); else internal_add(p->right, mid, r, idx, new_val); p->val = e(); if (p->left != nullptr) p->val = op(p->left->val, p->val); if (p->right != nullptr) p->val = op(p->val, p->right->val); } S internal_access(node*& p, const size_t& l, const size_t& r, const size_t& idx) { if (p == nullptr) { return e(); } if (r - l == 1) { return p->val; } size_t mid = (l + r) >> 1; if (idx < mid) return internal_access(p->left, l, mid, idx); else return internal_access(p->right, mid, r, idx); } S internal_prod(node*& p, const size_t& l, const size_t& r, const size_t& L, const size_t& R) { if (p == nullptr || r <= L || R <= l) { return e(); } if (L <= l && r <= R) { return p->val; } size_t mid = (l + r) >> 1; return op(internal_prod(p->left, l, mid, L, R), internal_prod(p->right, mid, r, L, R)); } }; #line 3 "main.cpp" int op(int x, int y) { return x + y; } int e() { return 0; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); const size_t n = 1000000001; dynamic_segtree seg(n); int q; cin >> q; long long ans = 0; while (q--) { int type; cin >> type; if (type == 0) { size_t x; long long y; cin >> x >> y; seg.add(x, y); } else { size_t l, r; cin >> l >> r; ans += seg.prod(l, r + 1); } } cout << ans << '\n'; }