#include #include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using uint = unsigned; using ull = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; template struct SegmentTree{ using T = typename M::T; int sz, n, height{}; vector seg; explicit SegmentTree(int n) : n(n) { sz = 1; while(sz < n) sz <<= 1, height++; seg.assign(2*sz, M::e()); } void set(int k, const T &x){ seg[k + sz] = x; } void build(){ for (int i = sz-1; i > 0; --i) seg[i] = M::f(seg[2*i], seg[2*i+1]); } void update(int k, const T &x){ k += sz; seg[k] = x; while (k >>= 1) seg[k] = M::f(seg[2*k], seg[2*k+1]); } T query(int a, int b){ T l = M::e(), r = M::e(); for(a += sz, b += sz; a < b; a >>=1, b>>=1){ if(a & 1) l = M::f(l, seg[a++]); if(b & 1) r = M::f(seg[--b], r); } return M::f(l, r); } template int search_right(int l, F cond){ if(l == n) return n; T val = M::e(); l += sz; do { while(!(l&1)) l >>= 1; if(!cond(M::f(val, seg[l]))){ while(l < sz) { l <<= 1; if (cond(M::f(val, seg[l]))){ val = M::f(val, seg[l]); l++; } } return l - sz; } val = M::f(val, seg[l]); l++; } while((l & -l) != l); return n; } template int search_left(int r, F cond){ if(r == 0) return 0; T val = M::e(); r += sz; do { r--; while(r&1) r >>= 1; if(!cond(M::f(seg[r], val))){ while(r < sz) { r = ((r << 1)|1); if (cond(M::f(seg[r], val))){ val = M::f(seg[r], val); r--; } } return r + 1 - sz; } val = M::f(seg[r], val); } while((r & -r) != r); return 0; } T operator[](const int &k) const { return seg[k + sz]; } }; struct Monoid{ using T = array; static T f(T a, T b) { // L, R, sum, ans return { max(a[0], b[0]+a[2]), max(b[1], a[1]+b[2]), a[2]+b[2], max({a[3], b[3], a[1]+max(0LL, b[0]), b[0]+max(0LL, a[1])}) }; } static T e() { return {-INF, -INF, -INF, -INF}; } }; int main() { int n; cin >> n; vector A(n), B(n); ll S = 0; vector z; z.emplace_back(0); for (int i = 0; i < n; ++i) { scanf("%lld %lld", &A[i], &B[i]); S += B[i]; z.emplace_back(S); } ll q; cin >> q; vector t(q), x(q), y(q); for (int i = 0; i < q; ++i) { scanf("%lld %lld %lld", &t[i], &x[i], &y[i]); if(t[i] == 1){ x[i]--; z.emplace_back(x[i]); z.emplace_back(x[i]+1); }else { x[i]--; z.emplace_back(x[i]); z.emplace_back(y[i]); } } sort(z.begin(), z.end()); z.erase(unique(z.begin(), z.end()), z.end()); auto f = [&](ll a){ return lower_bound(z.begin(),z.end(), a) - z.begin(); }; SegmentTree seg(z.size()); S = 0; for (int i = 0; i < n; ++i) { int l = f(S), r = f(S+B[i]); for (int j = l; j < r; ++j) { ll len = z[j+1]-z[j]; seg.set(j, { max(A[i], A[i]*len), max(A[i], A[i]*len), A[i]*len, max(A[i], A[i]*len) }); } S += B[i]; } seg.build(); for (int i = 0; i < q; ++i) { if(t[i] == 1){ int xx = f(x[i]); seg.update(xx, {y[i], y[i], y[i], y[i]}); }else { int l = f(x[i]), r = f(y[i]); auto [a, b, c, d] = seg.query(l, r); printf("%lld\n", max({a, b, d})); } } return 0; }