#include using namespace std; using uint = unsigned int; using lint = long long int; using ulint = unsigned long long int; template using V = vector; template using VV = V< V >; template void assign(V& v, int n, const U& a) { v.assign(n, a); } template void assign(V& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); } struct SumMonoid { using T = lint; static T op(const T& lhs, const T& rhs) { return lhs + rhs; } static constexpr T e() { return 0; } }; template struct AddMonoidAct { using T = lint; static void ap(const T& act, typename Monoid::T& val, int len) { val += act * len; } static void cp(const T& lhs, T& rhs) { rhs += lhs; } static constexpr T id() { return 0; } static bool is_id(const T& act) { return act == id(); } }; template struct SegmentTree { using M = Monoid; using MA = MonoidAct; using Tv = typename M::T; using Ta = typename MA::T; struct Node; using Tree = Node*; struct Node { Tv val = M::e(); Ta act = MA::id(); Tree cl, cr; }; const Int n; SegmentTree(Int n) : n(n), tree(new Node()) {} Tv get(Int l, Int r) { l = max(l, 0), r = min(r, n); if (l >= r) return M::e(); return get(l, r, tree, 0, n); } void set(Int l, Int r, const Ta& f) { l = max(l, 0), r = min(r, n); if (l >= r) return; set(l, r, f, tree, 0, n); } void set(Int i, const Tv& a) { assert(0 <= i and i < n); set(i, a, tree, 0, n); } private: Tree tree; void push(Tree& t, Int tl, Int tm, Int tr) { if (MA::is_id(t->act)) return; if (!t->cl) t->cl = new Node(); MA::ap(t->act, t->cl->val, tm - tl); MA::cp(t->act, t->cl->act); if (!t->cr) t->cr = new Node(); MA::ap(t->act, t->cr->val, tr - tm); MA::cp(t->act, t->cr->act); t->act = MA::id(); } Tv get(Int l, Int r, Tree t, Int tl, Int tr) { if (!t) return M::e(); if (l <= tl and tr <= r) return t->val; Int tm = tl + tr >> 1; push(t, tl, tm, tr); Tv resl = l < tm ? get(l, r, t->cl, tl, tm) : M::e(), resr = tm < r ? get(l, r, t->cr, tm, tr) : M::e(); return M::op(resl, resr); } void set(Int l, Int r, const Ta& f, Tree& t, Int tl, Int tr) { if (!t) t = new Node(); if (l <= tl and tr <= r) { MA::ap(f, t->val, tr - tl); MA::cp(f, t->act); return; } Int tm = tl + tr >> 1; push(t, tl, tm, tr); if (l < tm) set(l, r, f, t->cl, tl, tm); if (tm < r) set(l, r, f, t->cr, tm, tr); t->val = M::op(t->cl ? t->cl->val : M::e(), t->cr ? t->cr->val : M::e()); } void set(Int i, const Tv& a, Tree& t, Int tl, Int tr) { if (!t) t = new Node(); if (tr - tl == 1) { t->val = a; return; } Int tm = tl + tr >> 1; push(t, tl, tm, tr); if (i < tm) set(i, a, t->cl, tl, tm); else set(i, a, t->cr, tm, tr); t->val = M::op(t->cl ? t->cl->val : M::e(), t->cr ? t->cr->val : M::e()); } }; using ST = SegmentTree< SumMonoid, AddMonoidAct, lint >; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); ST st(1e9 + 1); lint res = 0; int n; cin >> n; while (n--) { int type; cin >> type; if (type == 0) { int x, y; cin >> x >> y; st.set(x, x + 1, y); } else { int l, r; cin >> l >> r, ++r; res += st.get(l, r); } } cout << res << '\n'; }