#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_lch() { if (!lch) { lch = std::make_unique(n / 2); } } void require_rch() { if (!rch) { 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 (i < n / 2) { if (!lch) return Monoid::zero; return lch->get(i); } else { if (!rch) return Monoid::zero; return rch->get(i - n / 2); } } void update(int i, value_type x) { assert(0 <= i && i < n); if (n == 1) { value = x; } else { if (i < n / 2) { require_lch(); lch->update(i, x); } else { require_rch(); rch->update(i - n / 2, x); } auto lv = lch ? lch->value : Monoid::zero, rv = rch ? rch->value : Monoid::zero; value = Monoid::product(lv, rv); } } value_type product(int from, int to) { if (to <= 0 || n <= from) return Monoid::zero; if (from <= 0 && n <= to) return value; require_lch(); require_rch(); auto lp = lch->product(from, to), rp = rch->product(from - n / 2, to - n / 2); return Monoid::product(lp, rp); } }; struct int_sum { using value_type = int; static constexpr value_type zero = 0; static value_type 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; }