#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return vector(arg, init); else return vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template auto distance(const Container &c, decltype(begin(c)) iter) { return distance(begin(c), iter); } template ::value_type>> auto isort(RIter first, RIter last, Compare comp = Compare()) { vector i(distance(first, last)); iota(begin(i), end(i), 0); sort(begin(i), end(i), [&](auto x, auto y) { return comp(*(first + x), *(first + y)); }); return i; } template typename, typename = void_t<>> struct detect : false_type {}; template typename Check> struct detect>> : true_type {}; template typename Check> constexpr inline bool detect_v = detect::value; template using has_member_sort = decltype(declval().sort()); template > auto sorted(Container c, Compare comp = Compare()) { if constexpr (detect_v) { c.sort(comp); return c; } else { sort(begin(c), end(c), comp); return c; } } template > auto uniqued(Container c, Compare comp = Compare()) { c.erase(unique(begin(c), end(c), comp), end(c)); return c; } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } template constexpr auto fix(F &&f) noexcept { return [f = std::tuple(std::forward(f))](auto &&...args) mutable { return std::get<0>(f)(fix(std::get<0>(f)), std::forward(args)...); }; } template struct dynamic_segment_tree { using value_type = S; dynamic_segment_tree(): dynamic_segment_tree(0) { } dynamic_segment_tree(std::size_t n): n_(n), root_(nullptr) { } ~dynamic_segment_tree() { if (root_ != nullptr) delete root_; } public: void set(std::size_t i, S x) { assert(0 <= i && i < n_); update_tree(root_, 0, n_, i, x); } S get(std::size_t i) const { assert(0 <= i && i < n_); return get(root_, 0, n_, i); } S prod(std::size_t l, std::size_t r) const { assert(0 <= l && l <= r && r <= n_); return prod(root_, 0, n_, l, r); } S all_prod() const { if (root_ != nullptr) { return root_->prod; } return E(); } template std::size_t max_right(std::size_t l, F &&f) const { static_assert(std::is_invocable_r_v); assert(0 <= l && l <= n_); assert(std::forward(f)(E())); S acc = E(); return max_right(root_, 0, n_, l, [&](auto &&x) mutable { return std::forward(f)(std::forward(x)); }, acc); } template std::size_t min_left(std::size_t r, F &&f) const { static_assert(std::is_invocable_r_v); assert(0 <= r && r <= n_); assert(std::forward(f)(E())); S acc = E(); return min_left(root_, 0, n_, r, [&](auto &&x) mutable { return std::forward(f)(std::forward(x)); }, acc); } private: struct node { node(std::size_t i, S value): i(i), value(value), prod(value), l(nullptr), r(nullptr) { } ~node() { if (l != nullptr) delete l; if (r != nullptr) delete r; } void update() { prod = Op(Op( l != nullptr ? l->prod : E(), value), r != nullptr ? r->prod : E() ); } std::size_t i; S value, prod; node *l, *r; }; static void update_tree(node* &range, std::size_t l, std::size_t r, std::size_t i, S x) { using std::swap; if (range == nullptr) { range = new node(i, x); return; } if (range->i == i) { range->value = x; range->update(); return; } auto m = l + (r - l) / 2; if (i < m) { if (range->i < i) { swap(range->i, i); swap(range->value, x); } update_tree(range->l, l, m, i, x); } else { if (i < range->i) { swap(range->i, i); swap(range->value, x); } update_tree(range->r, m, r, i, x); } range->update(); } static S get(const node *range, std::size_t l, std::size_t r, std::size_t i) { if (range == nullptr) { return E(); } if (range->i == i) { return range->value; } auto m = l + (r - l) / 2; if (i < m) { return get(range->l, l, m, i); } return get(range->r, m, r, i); } static S prod(const node *range, std::size_t l, std::size_t r, std::size_t query_l, std::size_t query_r) { if (range == nullptr || r <= query_l || query_r <= l) { return E(); } if (query_l <= l && r <= query_r) { return range->prod; } auto m = l + (r - l) / 2; S acc = prod(range->l, l, m, query_l, query_r); if (query_l <= range->i && range->i < query_r) { acc = Op(acc, range->value); } return Op(acc, prod(range->r, m, r, query_l, query_r)); } template static std::size_t max_right(const node *range, std::size_t l, std::size_t r, std::size_t query_l, F f, S &acc) { if (range == nullptr || r <= query_l) { return r; } auto m = l + (r - l) / 2; auto max_right_l = max_right(range->l, l, m, query_l, f, acc); if (max_right_l < m) { return max_right_l; } if (query_l <= range->i) { if (S con = Op(acc, range->value); f(con)) { acc = con; } else { return range->i; } } if (query_l <= m) { if (range->r == nullptr) { return r; } if (S con = Op(acc, range->r->prod); f(con)) { acc = con; return r; } } return max_right(range->r, m, r, query_l, f, acc); } template static std::size_t min_left(const node *range, std::size_t l, std::size_t r, std::size_t query_r, F f, S &acc) { if (range == nullptr || query_r <= l) { return l; } auto m = l + (r - l) / 2; auto min_left_r = min_left(range->r, m, r, query_r, f, acc); if (m < min_left_r) { return min_left_r; } if (range->i < query_r) { if (S con = Op(range->value, acc); f(con)) { acc = con; } else { return range->i + 1; } } if (m <= query_r) { if (range->l == nullptr) { return l; } if (S con = Op(range->l->prod, acc); f(con)) { acc = con; return l; } } return min_left(range->l, l, m, query_r, f, acc); } private: std::size_t n_; node *root_; }; int64_t op(int64_t x, int64_t y) { return x + y; } int64_t elem() { return 0; } using segtree = dynamic_segment_tree; int main() { constexpr auto lim = 1000000001; int n; cin >> n; int64_t ans = 0; segtree seg(lim); while (n--) { int t; cin >> t; if (t == 0) { int x, y; cin >> x >> y; seg.set(x, seg.get(x) + y); } if (t == 1) { int l, r; cin >> l >> r; ++r; ans += seg.prod(l, r); } } cout << ans << endl; }