func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int RLEN = 1 << 20 | 1;   inline char gc() {     static char ibuf[RLEN], *ib, *ob;     (ob == ib) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));     return (ob == ib) ? EOF : *ib++;   }   inline int read() {     char ch = getchar();     int res = 0, f = 1;     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = getchar();     return f ? res : -res;   }   inline void chemx(int &a, int b) { a < b ? a = b : 0; }   inline void chemn(int &a, int b) { a > b ? a = b : 0; }   struct node {     int s, m, r, t;     node(int _s = 0, int _m = 0, int _r = 0, int _t = 0)         : s(_s), m(_m), r(_r), t(_t) {}     friend inline bool operator<(const node &a, const node &b) {       return a.t < b.t;     }     friend inline bool operator==(const node &a, const node &b) {       return a.t == b.t;     }     friend inline bool operator>(const node &a, const node &b) {       return a.t > b.t;     }     friend inline bool operator<=(const node &a, const node &b) {       return a.t <= b.t;     }     friend inline bool operator>=(const node &a, const node &b) {       return a.t >= b.t;     }     friend inline bool operator!=(const node &a, const node &b) {       return a.t != b.t;     }   };   const int N = 100005, inf = 2e9;   node a[N];   int n, q;   struct Tr {     vector<node> v;     vector<long long> sl, sr;     int last;     inline void init(int l, int r) {       int len = r - l + 1;       for (int i = l; i <= r; i++) v.push_back(a[i]);       sort(v.begin(), v.end());       sl.resize(len), sr.resize(len);       sl[0] = v[0].m, sr[len - 1] = v[len - 1].r;       for (int i = 1; i < len; i++) sl[i] = sl[i - 1] + v[i].m;       for (int i = len - 2; ~i; i--) sr[i] = sr[i + 1] + v[i].r;     }     inline long long query(int t) {       int tim = t - last;       int pos =           lower_bound(v.begin(), v.end(), node(0, 0, 0, tim)) - v.begin() - 1;       long long res = 0;       if (~pos) res += sl[pos];       if (pos + 1 < (int)v.size()) res += sr[pos + 1] * tim;       last = t;       return res;     }   };   namespace Seg {   Tr tr[N << 2];   void build(int u, int l, int r) {     tr[u].last = -2, tr[u].init(l, r);     if (l == r) return;     build((u << 1), l, ((l + r) >> 1)),         build(((u << 1) | 1), ((l + r) >> 1) + 1, r);   }   inline void pushup(int u) {     if (tr[(u << 1)].last == tr[((u << 1) | 1)].last)       if (tr[(u << 1)].last >= 0) {         tr[u].last = tr[(u << 1)].last;         return;       } else if (tr[(u << 1)].last == -2) {         tr[u].last = -2;         return;       }     tr[u].last = -1;   }   inline void pushdown(int u) {     if (tr[u].last >= 0) tr[(u << 1)].last = tr[((u << 1) | 1)].last = tr[u].last;   }   long long query(int u, int l, int r, int st, int des, int k) {     if (l == r && tr[u].last == -2) {       tr[u].last = k;       return min(1ll * a[l].m, 1ll * a[l].s + 1ll * a[l].r * k);     }     if (st <= l && r <= des && tr[u].last >= 0) return tr[u].query(k);     long long res = 0;     pushdown(u);     if (st <= ((l + r) >> 1))       res += query((u << 1), l, ((l + r) >> 1), st, des, k);     if (((l + r) >> 1) < des)       res += query(((u << 1) | 1), ((l + r) >> 1) + 1, r, st, des, k);     pushup(u);     return res;   }   }  // namespace Seg   int main() {     n = read();     for (int i = 1; i <= n; i++) {       a[i].s = read(), a[i].m = read(), a[i].r = read(),       a[i].t = a[i].r == 0 ? inf : a[i].m / a[i].r;     }     Seg::build(1, 1, n);     q = read();     while (q--) {       int t = read(), l = read(), r = read();       cout << Seg::query(1, 1, n, l, r, t) <<   n ;     }   }   