func_code_string: #include <bits/stdc++.h>   using namespace std;   int n;   struct SegTree {     int L, R, P, DELTA;     struct node {       int d;       bool zero;     } v[212345 * 4];     inline void set_zero(int x) {       v[x].zero = 1;       v[x].d = 0;     }     inline void fix(int x, int d) {       v[x].zero = 0;       v[x].d += d;     }     inline void rep(int x) {       if (v[x].zero) {         set_zero(x * 2);         set_zero(x * 2 + 1);         v[x].zero = 0;       } else {         fix(x * 2, v[x].d);         fix(x * 2 + 1, v[x].d);         v[x].d = 0;       }     }     void update(int x, int l, int r) {       if (l > R || r < L) return;       if (L <= l && r <= R) {         if (l < r)           rep(x);         else           v[x].zero = 0;         v[x].d += DELTA;         return;       }       int m = (l + r) / 2;       rep(x);       update(x * 2, l, m);       update(x * 2 + 1, m + 1, r);     }     void gao_zero(int x, int l, int r) {       if (l > R || r < L) return;       if (L <= l && r <= R) {         set_zero(x);         return;       }       int m = (l + r) / 2;       rep(x);       gao_zero(x * 2, l, m);       gao_zero(x * 2 + 1, m + 1, r);     }     int add(int x, int y) {       if (~y) return x + y;       return -1;     }     int query(int x, int l, int r) {       if (v[x].zero) return -1;       if (l == r) return v[x].d;       int m = (l + r) / 2;       if (P <= m)         return add(v[x].d, query(x * 2, l, m));       else         return add(v[x].d, query(x * 2 + 1, m + 1, r));     }     void up(int l, int r, int d) {       L = l, R = r, DELTA = d;       update(1, 1, n);     }     void zero(int l, int r) {       L = l, R = r;       gao_zero(1, 1, n);     }     int qr(int p) {       P = p;       return query(1, 1, n);     }   } tree;   int x[212345], len[212345];   vector<pair<int, int> > qu[212345];   int ans[212345], nxt[212345];   int L[212345], D[212345], id[212345], top = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , x + i, len + i);     int q;     scanf( %d , &q);     for (int i = 0; i < int(q); i++) {       int u, v;       scanf( %d%d , &u, &v);       qu[u].push_back(make_pair(v, i));     }     nxt[n] = -1;     for (int i = n - 1; i >= 1; --i) {       int j = i + 1;       while (~j && x[j] + len[j] <= x[i] + len[i]) j = nxt[j];       nxt[i] = j;     }     for (int i = n; i >= 1; --i) {       if (nxt[i] == -1) {       } else {         while (top > 0 && id[top] < nxt[i]) {           tree.up(L[top], n, -D[top]);           --top;         }         if (x[i] + len[i] >= x[nxt[i]]) {         } else {           tree.up(nxt[i], n, x[nxt[i]] - x[i] - len[i]);           ++top;           L[top] = nxt[i];           D[top] = x[nxt[i]] - x[i] - len[i];           id[top] = i;         }       }       for (auto x : qu[i]) ans[x.second] = tree.qr(x.first);     }     for (int i = 0; i < int(q); i++) printf( %d n , ~ans[i] ? ans[i] : 0);   }   