#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using lint = long long; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i std::vector sort_unique(std::vector vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } template int arglb(const std::vector &v, const T &x) { return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x)); } template int argub(const std::vector &v, const T &x) { return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x)); } #include constexpr lint inf = 1LL << 60; struct S { lint sum = 0; lint lmax = 0; lint rmax = 0; lint inmax = 0; lint single_max = -inf; static S init(lint val, lint len) { return S{val * len, max(val, 0LL) * len, max(val, 0LL) * len, max(val, 0LL) * len, val}; } lint get() const { return single_max >= 0 ? inmax : single_max; } }; S op(S l, S r) { return { l.sum + r.sum, max(l.lmax, l.sum + r.lmax), max(r.rmax, r.sum + l.rmax), max({l.inmax, r.inmax, l.rmax + r.lmax}), max(l.single_max, r.single_max), }; } S e() { return S(); } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; cin >> N; vector A(N), B(N); vector xs; lint r = 0; xs.push_back(r); REP(i, N) { cin >> A.at(i) >> B.at(i); r += B.at(i); xs.push_back(r); } const auto heads = xs; int Q; cin >> Q; vector> qs; REP(q, Q) { int tp; cin >> tp; if (tp == 1) { lint x, y; cin >> x >> y; --x; xs.push_back(x); xs.push_back(x + 1); qs.emplace_back(tp, x, y); } else { lint l, r; cin >> l >> r; --l; xs.push_back(l), xs.push_back(r); qs.emplace_back(tp, l, r); } } xs = sort_unique(xs); vector init; FOR(i, 1, xs.size()) { const lint xl = xs.at(i - 1), xr = xs.at(i); const int d = argub(heads, xl) - 1; init.push_back(S::init(A.at(d), xr - xl)); } atcoder::segtree tree(init); for (auto [tp, l, r] : qs) { if (tp == 1) { tree.set(arglb(xs, l), S::init(r, 1)); } else { cout << tree.prod(arglb(xs, l), arglb(xs, r)).get() << '\n'; } } }