#include #include #define NDEBUG #include template class segtree_node { public: using value_type = typename Monoid::value_type; private: using node_t = std::unique_ptr>; node_t lch, rch; int n; value_type value; void require_children() { if (!lch) { lch = std::make_unique(n / 2); rch = std::make_unique(n - n / 2); } } public: segtree_node(int n): n(n), value(Monoid::zero) {} value_type get(int i) { assert(0 <= i && i < n); if (n == 1) { return value; } else if (!lch) { return Monoid::zero; } else if (i < n / 2) { return lch->get(i); } else { return rch->get(i - n / 2); } } void update(int i, value_type x) { assert(0 <= i && i < n); if (n == 1) { value = x; } else { require_children(); if (i < n / 2) lch->update(i, x); else rch->update(i - n / 2, x); value = Monoid::product(lch->value, rch->value); } } value_type product(int from, int to) { if (to <= 0 || n <= from) return Monoid::zero; if (from <= 0 && n <= to) return value; require_children(); auto lp = lch->product(from, to), rp = rch->product(from - n / 2, to - n / 2); return Monoid::product(lp, rp); } }; struct ll_sum { using value_type = long long; static constexpr value_type zero = 0; static long long product(value_type x, value_type y) { return x + y; } }; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; int t, x, y; segtree_node segtree(1000000001); long long sum = 0; for (int i = 0; i < n; i++) { std::cin >> t >> x >> y; if (t == 0) { auto current = segtree.get(x); segtree.update(x, current + y); } else { sum += segtree.product(x, y + 1); } } std::cout << sum << std::endl; }