func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, sl, fh;   struct node {     int s, m, r, t;   } a[100010];   struct seg {     vector<long long> tim, pre, suf;     vector<node> a;     int lt;     void resize(int l) {       pre.resize(l);       suf.resize(l);     }     long long getans(int T) {       if (!lt) {         long long ret = 0;         for (int i = 0; i < (int)a.size(); ++i)           ret += min(0ll + a[i].m, a[i].s + 1ll * T * a[i].r);         lt = T;         return ret;       }       int t = T - lt,           p = upper_bound(tim.begin(), tim.end(), t) - tim.begin() - 1;       long long ret = 0;       if (p >= 0) ret = pre[p];       if (p < (int)a.size() - 1) ret += t * suf[p + 1];       lt = T;       return ret;     }   } tr[100010 << 2];   int rd() {     sl = 0;     fh = 1;     char ch = getchar();     while (ch <  0  ||  9  < ch) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) sl = sl * 10 + ch -  0 , ch = getchar();     return sl * fh;   }   void merge(seg &res, seg &x, seg &y) {     int sz, sx = x.a.size(), sy = y.a.size();     res.resize(sz = sx + sy);     int i = 0, j = 0;     for (; i < sx && j < sy;)       if (x.tim[i] <= y.tim[j])         res.a.push_back(x.a[i]), res.tim.push_back(x.tim[i]), ++i;       else         res.a.push_back(y.a[j]), res.tim.push_back(y.tim[j]), ++j;     for (; i < sx; ++i) res.a.push_back(x.a[i]), res.tim.push_back(x.tim[i]);     for (; j < sy; ++j) res.a.push_back(y.a[j]), res.tim.push_back(y.tim[j]);     res.pre[0] = res.a[0].m;     for (int i = 1; i < sz; ++i) res.pre[i] = res.pre[i - 1] + res.a[i].m;     res.suf[sz - 1] = res.a[sz - 1].r;     for (int i = sz - 1; i; --i) res.suf[i - 1] = res.suf[i] + res.a[i - 1].r;   }   void build(int x, int l, int r) {     if (l == r) {       tr[x].a.push_back(a[l]);       tr[x].tim.push_back(a[l].t);       tr[x].pre.push_back(a[l].m);       tr[x].suf.push_back(a[l].r);       return;     }     build(x << 1, l, ((l + r) >> 1));     build(x << 1 | 1, ((l + r) >> 1) + 1, r);     merge(tr[x], tr[x << 1], tr[x << 1 | 1]);   }   void pushdown(int x) {     if (tr[x].lt >= 0) tr[x << 1].lt = tr[x << 1 | 1].lt = tr[x].lt, tr[x].lt = 0;   }   long long query(int x, int l, int r, int L, int R, int T) {     if (L <= l && r <= R && tr[x].lt >= 0) return tr[x].getans(T);     pushdown(x);     tr[x].lt = -1;     long long ret = 0;     if (L <= ((l + r) >> 1)) ret = query(x << 1, l, ((l + r) >> 1), L, R, T);     if (R > ((l + r) >> 1))       ret += query(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R, T);     if (tr[x << 1].lt == tr[x << 1 | 1].lt) tr[x].lt = tr[x << 1].lt;     return ret;   }   int main() {     n = rd();     for (int i = 1; i <= n; ++i) {       a[i].s = rd();       a[i].m = rd();       a[i].r = rd();       if (!a[i].r)         a[i].t = 1e9;       else         a[i].t = (a[i].m - 1) / a[i].r + 1;     }     build(1, 1, n);     for (int l, r, t, T = rd(); T; --T) {       t = rd();       l = rd();       r = rd();       printf( %lld n , query(1, 1, n, l, r, t));     }     return 0;   }   