#line 2 "library/other/template.hpp" #include #ifndef __COUNTER__ #define __COUNTER__ __LINE__ #endif #define REP_SELECTER(a, b, c, d, e, ...) e #define REP1_0(b, c) REP1_1(b, c) #define REP1_1(b, c) for (ll REP_COUNTER_ ## c = 0; REP_COUNTER_ ## c < (ll)(b); ++ REP_COUNTER_ ## c) #define REP1(b) REP1_0(b, __COUNTER__) #define REP2(i, b) for (ll i = 0; i < (ll)(b); ++i) #define REP3(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define REP4(i, a, b, c) for (ll i = (ll)(a); i < (ll)(b); i += (ll)(c)) #define rep(...) REP_SELECTER(__VA_ARGS__, REP4, REP3, REP2, REP1) (__VA_ARGS__) #define RREP2(i, a) for (ll i = (ll)(a) - 1; i >= 0; --i) #define RREP3(i, a, b) for (ll i = (ll)(a) - 1; i >= (ll)(b); --i) #define RREP4(i, a, b, c) for (ll i = (ll)(a) - 1; i >= (ll)(b); i -= (ll)(c)) #define rrep(...) REP_SELECTER(__VA_ARGS__, RREP4, RREP3, RREP2) (__VA_ARGS__) #define REPS2(i, b) for (ll i = 1; i <= (ll)(b); ++i) #define REPS3(i, a, b) for (ll i = (ll)(a) + 1; i <= (ll)(b); ++i) #define REPS4(i, a, b, c) for (ll i = (ll)(a) + 1; i <= (ll)(b); i += (ll)(c)) #define reps(...) REP_SELECTER(__VA_ARGS__, REPS4, REPS3, REPS2) (__VA_ARGS__) #define RREPS2(i, a) for (ll i = (ll)(a); i > 0; --i) #define RREPS3(i, a, b) for (ll i = (ll)(a); i > (ll)(b); --i) #define RREPS4(i, a, b, c) for (ll i = (ll)(a); i > (ll)(b); i -= (ll)(c)) #define rreps(...) REP_SELECTER(__VA_ARGS__, RREPS4, RREPS3, RREPS2) (__VA_ARGS__) #define all(v) (v).begin(), (v).end() #if __cplusplus >= 201402L #define CONSTEXPR constexpr #else #define CONSTEXPR #endif #ifdef __cpp_if_constexpr #define IF_CONSTEXPR constexpr #else #define IF_CONSTEXPR #endif using ll = long long; using ull = unsigned long long; using ld = long double; using PLL = std::pair; template using prique = std::priority_queue, std::greater>; template class infinity { public: static constexpr T value = std::numeric_limits::max() / 2; static constexpr T mvalue = std::numeric_limits::min() / 2; static constexpr T max = std::numeric_limits::max(); static constexpr T min = std::numeric_limits::min(); }; #if __cplusplus <= 201402L template constexpr T infinity::value; template constexpr T infinity::mvalue; template constexpr T infinity::max; template constexpr T infinity::min; #endif #if __cplusplus >= 201402L template constexpr T INF = infinity::value; #endif constexpr ll inf = infinity::value; constexpr ld EPS = 1e-8; constexpr ld PI = 3.1415926535897932384626; template std::ostream& operator<<(std::ostream& ost, const std::pair& p) { return ost << p.first << ' ' << p.second; } template std::istream& operator>>(std::istream& ist, std::pair& p) { return ist >> p.first >> p.second; } template::value>::type* = nullptr> auto operator<<(std::ostream& ost, const Container& cont) -> decltype(cont.begin(), cont.end(), ost) { for (auto itr = cont.begin(); itr != cont.end(); ++itr) { if (itr != cont.begin()) ost << ' '; ost << *itr; } return ost; } template::value>::type* = nullptr> auto operator>>(std::istream& ist, Container& cont) -> decltype(cont.begin(), cont.end(), ist) { for (auto itr = cont.begin(); itr != cont.end(); ++itr) ist >> *itr; return ist; } template inline constexpr bool chmin(T &a, const U &b) noexcept { return a > b ? a = b, true : false; } template inline constexpr bool chmax(T &a, const U &b) noexcept { return a < b ? a = b, true : false; } inline CONSTEXPR ll gcd(ll a, ll b) noexcept { while (b) { const ll c = a; a = b; b = c % b; } return a; } inline CONSTEXPR ll lcm(ll a, ll b) noexcept { return a / gcd(a, b) * b; } inline CONSTEXPR bool is_prime(ll N) noexcept { if (N <= 1) return false; for (ll i = 2; i * i <= N; ++i) { if (N % i == 0) return false; } return true; } inline std::vector prime_factor(ll N) noexcept { std::vector res; for (ll i = 2; i * i <= N; ++i) { while (N % i == 0) { res.push_back(i); N /= i; } } if (N != 1) res.push_back(N); return res; } inline CONSTEXPR ll my_pow(ll a, ll b) noexcept { ll res = 1; while (b) { if (b & 1) res *= a; b >>= 1; a *= a; } return res; } inline CONSTEXPR ll mod_pow(ll a, ll b, ll mod) noexcept { a %= mod; ll res = 1; while (b) { if (b & 1) (res *= a) %= mod; b >>= 1; (a *= a) %= mod; } return res; } PLL extGCD(ll a, ll b) noexcept { if (b == 0) return PLL{1, 0}; PLL p = extGCD(b, a % b); std::swap(p.first, p.second); p.second -= p.first * (a / b); if (p.first < 0) { p.first += b; p.second -= a; } return p; } ll mod_inv(ll a, ll mod) noexcept { const PLL p = extGCD(a, mod); assert(p.first * a + p.second * mod == 1); return p.first; } PLL ChineseRemainder(ll b1, ll m1, ll b2, ll m2) noexcept { const PLL p = extGCD(m1, m2); const ll g = p.first * m1 + p.second * m2; const ll l = m1 / g * m2; if ((b2 - b1) % g != 0) return PLL{-1, -1}; const ll x = (b2 - b1) / g * p.first % (m2 / g); return {(x * m1 + b1 + l) % l, l}; } PLL ChineseRemainders(const std::vector& b, const std::vector& m) noexcept { PLL res{0, 1}; rep (i, b.size()) { res = ChineseRemainder(res.first, res.second, b[i], m[i]); if (res.first == -1) return res; } return res; } template class RecLambda { private: F f; public: explicit constexpr RecLambda(F&& f_) : f(std::forward(f_)) {} template constexpr auto operator()(Args&&... args) const -> decltype(f(*this, std::forward(args)...)) { return f(*this, std::forward(args)...); } }; template inline constexpr RecLambda rec_lambda(F&& f) { return RecLambda(std::forward(f)); } template struct multi_dim_vector { using type = std::vector::type>; }; template struct multi_dim_vector { using type = T; }; template constexpr std::vector make_vec(int n, Arg&& arg) { return std::vector(n, std::forward(arg)); } template constexpr typename multi_dim_vector::type make_vec(int n, Args&&... args) { return typename multi_dim_vector::type (n, make_vec(std::forward(args)...)); } inline CONSTEXPR int popcnt(ull x) { #if __cplusplus >= 202002L return std::popcount(x); #endif x = (x & 0x5555555555555555) + ((x >> 1 ) & 0x5555555555555555); x = (x & 0x3333333333333333) + ((x >> 2 ) & 0x3333333333333333); x = (x & 0x0f0f0f0f0f0f0f0f) + ((x >> 4 ) & 0x0f0f0f0f0f0f0f0f); x = (x & 0x00ff00ff00ff00ff) + ((x >> 8 ) & 0x00ff00ff00ff00ff); x = (x & 0x0000ffff0000ffff) + ((x >> 16) & 0x0000ffff0000ffff); return (x & 0x00000000ffffffff) + ((x >> 32) & 0x00000000ffffffff); } template class presser : public std::vector { private: using Base = std::vector; public: using Base::Base; presser(const std::vector& vec) : Base(vec) {} void push(const std::vector& vec) { int n = this->size(); this->resize(n + vec.size()); std::copy(all(vec), this->begin() + n); } int build() { std::sort(this->begin(), this->end()); this->erase(std::unique(this->begin(), this->end()), this->end()); return this->size(); } int get_index(const T& val) const { return static_cast(std::lower_bound(this->begin(), this->end(), val) - this->begin()); } std::vector pressed(const std::vector& vec) const { std::vector res(vec.size()); rep (i, vec.size()) res[i] = this->get_index(vec[i]); return res; } void press(std::vector& vec) const { static_assert(std::is_integral::value, "cannot convert from int type"); rep (i, vec.size()) vec[i] = this->get_index(vec[i]); } }; #line 2 "library/data-struct/segment/DynamicSegmentTree.hpp" #line 2 "library/other/bitop.hpp" #line 4 "library/other/bitop.hpp" namespace bitop { #define KTH_BIT(b, k) (((b) >> (k)) & 1) #define POW2(k) (1ull << (k)) inline ull next_combination(int n, ull x) { if (n == 0) return 1; ull a = x & -x; ull b = x + a; return (x & ~b) / a >> 1 | b; } #define rep_comb(i, n, k) for (ull i = (1ull << (k)) - 1; i < (1ull << (n)); i = bitop::next_combination((n), i)) inline CONSTEXPR int msb(ull x) { int res = x ? 0 : -1; if (x & 0xFFFFFFFF00000000) x &= 0xFFFFFFFF00000000, res += 32; if (x & 0xFFFF0000FFFF0000) x &= 0xFFFF0000FFFF0000, res += 16; if (x & 0xFF00FF00FF00FF00) x &= 0xFF00FF00FF00FF00, res += 8; if (x & 0xF0F0F0F0F0F0F0F0) x &= 0xF0F0F0F0F0F0F0F0, res += 4; if (x & 0xCCCCCCCCCCCCCCCC) x &= 0xCCCCCCCCCCCCCCCC, res += 2; return res + ((x & 0xAAAAAAAAAAAAAAAA) ? 1 : 0); } inline CONSTEXPR int ceil_log2(ull x) { return x ? msb(x - 1) + 1 : 0; } } #line 2 "library/other/monoid.hpp" #line 4 "library/other/monoid.hpp" namespace Monoid { template struct Sum { using value_type = T; static constexpr T op(T a, T b) { return a + b; } static constexpr T id() { return T{0}; } static constexpr T inv(T a, T b) { return a - b; } static constexpr T get_inv(T a) { return -a; } }; template::max> struct Min { using value_type = T; static constexpr T op(T a, T b) { return a > b ? b : a; } static constexpr T id() { return max_value; } }; template::min> struct Max { using value_type = T; static constexpr T op(T a, T b) { return a < b ? b : a;} static constexpr T id() { return min_value; } }; template struct Assign { using value_type = T; static constexpr T op(T a, T b) { return b; } }; template::max> struct AssignMin { using M = Min; using E = Assign; static constexpr T op(T a, T b) { return a; } static constexpr T mul(T a, int b) { return a; } static constexpr T mul_op(T a, int b, T c) { return a; } }; template::min> struct AssignMax { using M = Max; using E = Assign; static constexpr T op(T a, T b) { return a; } static constexpr T mul(T a, int b) { return a; } static constexpr T mul_op(T a, int b, T c) { return a; } }; template struct AssignSum { using M = Sum; using E = Assign; static constexpr T op(T a, T b) { return a; } static constexpr T mul(T a, int b) { return a * b; } static constexpr T mul_op(T a, int b, T c) { return a * b; } }; template::max> struct AddMin { using M = Min; using E = Sum; static constexpr T op(T a, T b) { return b + a; } static constexpr T mul(T a, int b) { return a; } static constexpr T mul_op(T a, int b, T c) { return c + a; } }; template::min> struct AddMax { using M = Max; using E = Sum; static constexpr T op(T a, T b) { return b + a; } static constexpr T mul(T a, int b) { return a; } static constexpr T mul_op(T a, int b, T c) { return c + a; } }; template struct AddSum { using M = Sum; using E = Sum; static constexpr T op(T a, T b) { return b + a; } static constexpr T mul(T a, int b) { return a * b; } static constexpr T mul_op(T a, int b, T c) { return c + a * b; } }; template::max> struct ChminMin { using M = Min; using E = Min; static constexpr T op(T a, T b) { return std::min(b, a); } static constexpr T mul(T a, int b) { return a; } static constexpr T mul_op(T a, int b, T c) { return std::min(c, a); } }; template::min> struct ChminMax { using M = Max; using E = Min; static constexpr T op(T a, T b) { return std::min(b, a); } static constexpr T mul(T a, int b) { return a; } static constexpr T mul_op(T a, int b, T c) { return std::min(c, a); } }; template::max> struct ChmaxMin { using M = Min; using E = Max; static constexpr T op(T a, T b) { return std::max(b, a); } static constexpr T mul(T a, int b) { return a; } static constexpr T mul_op(T a, int b, T c) { return std::max(c, a); } }; template::min> struct ChmaxMax { using M = Max; using E = Max; static constexpr T op(T a, T b) { return std::max(b, a); } static constexpr T mul(T a, int b) { return a; } static constexpr T mul_op(T a, int b, T c) { return std::max(c, a); } }; template struct AttachEffector { using M = M_; using E = M_; using T = typename M_::value_type; static T op(const T& a, const T& b) { return M_::op(b, a); } }; template struct AttachMonoid { using M = E_; using E = E_; using T = typename E_::value_type; static T op(const T& a, const T& b) { return E_::op(b, a); } }; template class has_id : public std::false_type {}; template class has_id : public std::true_type {}; template class has_inv : public std::false_type {}; template class has_inv : public std::true_type {}; template class has_get_inv : public std::false_type {}; template class has_get_inv : public std::true_type {}; template class has_mul : public std::false_type {}; template class has_mul : public std::true_type {}; template class has_mul_op : public std::false_type {}; template class has_mul_op : public std::true_type {}; template class is_semigroup : public std::false_type {};; template class is_semigroup(), (void)T::op)> : public std::true_type {}; template class is_monoid : public std::false_type {};; template class is_monoid(), (void)T::op, (void)T::id)> : public std::true_type {}; template class is_group : public std::false_type {};; template class is_group(), (void)T::op, (void)T::id, (void)T::get_inv)> : public std::true_type {}; template class is_action : public std::true_type {}; template class is_action(), std::declval(), (void)T::op)> : public std::false_type {}; } // namespace Monoid #line 6 "library/data-struct/segment/DynamicSegmentTree.hpp" template class DynamicSegmentTree { protected: using T = typename M::value_type; struct Node { T val; Node *l, *r; Node* get_l() { if (l == nullptr) l = new Node; return l; } Node* get_r() { if (r == nullptr) r = new Node; return r; } void update() { val = M::id(); if (l != nullptr) val = M::op(val, l->val); if (r != nullptr) val = M::op(val, r->val); } Node() : val(M::id()), l(nullptr), r(nullptr) {} }; T get_val(Node* nd) const { return nd == nullptr ? M::id() : nd->val; } ll n, h, ori; Node* root; template void update(Node* nd, ll a, ll b, ll k, const Upd& upd) { if (a + 1 == b) { nd->val = upd(nd->val); return; } ll m = (a + b) >> 1; if (k < m) update(nd->get_l(), a, m, k, upd); else update(nd->get_r(), m, b, k, upd); nd->update(); } T prod(Node* nd, ll a, ll b, ll l, ll r) const { if (nd == nullptr) return M::id(); if (l <= a && b <= r) return nd->val; if (r <= a || b <= l) return M::id(); ll m = (a + b) >> 1; return M::op(prod(nd->l, a, m, l, r), prod(nd->r, m, b, l, r)); } void del(Node* nd) { if (nd == nullptr) return; del(nd->l); del(nd->r); delete nd; } public: DynamicSegmentTree() : DynamicSegmentTree(inf >> 1) {} DynamicSegmentTree(ll n_) { init(n_); } ~DynamicSegmentTree() { del(root); } void init(ll n_) { ori = n_; h = bitop::ceil_log2(ori); n = 1 << h; root = new Node; } template void update(ll k, const Upd& upd) { assert(0 <= k && k < ori); update(root, 0, n, k, upd); } void set(ll k, T x) { update(k, [&](T) -> T { return x; }); } void apply(ll k, T x) { update(k, [&](T a) -> T { return M::op(a, x); }); } T prod(ll l, ll r) const { assert(0 <= l && l <= r && r <= ori); return prod(root, 0, n, l, r); } T all_prod() const { return root->val; } T get(ll k) const { return prod(k, k + 1); } }; /** * @brief DynamicSegmentTree(動的セグメント木) * @docs docs/DynamicSegmentTree.md */ #line 3 "main.cpp" using namespace std; int main() { int N; cin >> N; DynamicSegmentTree> seg; ll ans = 0; rep (N) { int t; cin >> t; if (t == 0) { ll a, b; cin >> a >> b; seg.apply(a, b); } else { ll l, r; cin >> l >> r; ans += seg.prod(l, r + 1); } } cout << ans << endl; }