func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 200100;   const long long INF = 0x3f3f3f3f3f3f3f3f;   long long d[MAXN], h[MAXN];   long long sd[MAXN];   struct str {     long long pfx, sfx, rnode, l, r;   };   struct st {     st *fe, *fd;     long long l, r, meio, pfx, sfx, rnode;     st(long long x, long long y) {       meio = (x + y) / 2;       pfx = sfx = rnode = 0;       l = x, r = y;       if (x == y) return;       fe = new st(x, meio);       fd = new st(meio + 1, y);     }     st(st *node) {       fe = node->fe;       fd = node->fd;       rnode = node->rnode;       pfx = node->pfx;       sfx = node->sfx;       l = node->l;       r = node->r;     }     void update(long long pos, long long novo) {       if (l == r) {         pfx = sfx = rnode = 2 * novo;         return;       }       if (pos <= meio)         fe->update(pos, novo);       else         fd->update(pos, novo);       pfx = max(fe->pfx, sd[fe->r] - sd[fe->l - 1] + fd->pfx);       sfx = max(fd->sfx, sd[fd->r - 1] - sd[fd->l - 1] + d[fe->r] + fe->sfx);       rnode = max(fe->rnode, max(fd->rnode, fe->sfx + fd->pfx + d[fe->r]));     }     str get(long long a, long long b) {       if (l >= a && r <= b) {         str resp;         resp.pfx = pfx;         resp.sfx = sfx;         resp.rnode = rnode;         resp.l = l;         resp.r = r;         return resp;       }       if (l > b || r < a) {         str at;         at.rnode = -INF;         at.pfx = -INF;         at.sfx = -INF;         return at;       }       str left = fe->get(a, b), right = fd->get(a, b);       str resp;       bool flag = false;       if (left.rnode < 0)         resp = right, flag = true;       else if (right.rnode < 0)         resp = left, flag = true;       if (flag == true) {         return resp;       }       resp.pfx = max(left.pfx, sd[left.r] - sd[left.l - 1] + right.pfx);       resp.sfx = max(right.sfx,                      sd[right.r - 1] - sd[right.l - 1] + d[left.r] + left.sfx);       resp.rnode =           max(left.rnode, max(right.rnode, left.sfx + right.pfx + d[left.r]));       resp.l = left.l, resp.r = right.r;       return resp;     }   };   st arvore(1, MAXN);   signed main() {     memset(sd, 0, sizeof sd);     long long n, q;     cin >> n >> q;     for (long long i = 1; i <= n; i++) cin >> d[i];     for (long long i = 1; i <= n; i++) cin >> h[i];     sd[0] = 0;     for (long long i = n + 1; i <= 2 * n; i++) d[i] = d[i - n], h[i] = h[i - n];     for (long long i = 1; i <= 2 * n; i++) sd[i] = sd[i - 1] + d[i];     for (long long i = 1; i <= 2 * n; i++) arvore.update(i, h[i]);     for (long long i = 1; i <= q; i++) {       long long x, y;       cin >> x >> y;       if (x > y)         cout << arvore.get(y + 1, x - 1).rnode << endl;       else         cout << arvore.get(y + 1, x + n - 1).rnode << endl;     }   }   