func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m;   long long dd[200000], h[200000];   int a, b;   int aaa[100000], bbb[100000];   long long d[200000];   long long mmin[200000][18], mmax[200000][18];   long long xxx(int x) { return h[x] - d[x]; }   long long yyy(int y) { return h[y] + d[y]; }   long long xval(int aa, int bb) {     int llog = 0;     while ((bb + 1 - aa) >= (1 << llog)) {       llog++;     }     llog--;     if (xxx(mmax[aa][llog]) >= xxx(mmax[bb + 1 - (1 << llog)][llog])) {       return mmax[aa][llog];     } else {       return mmax[bb + 1 - (1 << llog)][llog];     }   }   long long yval(int aa, int bb) {     int llog = 0;     while ((bb + 1 - aa) >= (1 << llog)) {       llog++;     }     llog--;     if (yyy(mmin[aa][llog]) >= yyy(mmin[bb + 1 - (1 << llog)][llog])) {       return mmin[aa][llog];     } else {       return mmin[bb + 1 - (1 << llog)][llog];     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> dd[i];     }     for (int i = 0; i < n; i++) {       cin >> h[i];       h[i] *= 2;     }     d[0] = dd[n - 1];     for (int i = 0; i < n - 1; i++) {       d[i + 1] = d[i] + dd[i];     }     for (int i = 0; i < n; i++) {       d[i + n] = d[i] + d[n - 1];       h[i + n] = h[i];     }     n *= 2;     for (int i = 0; i < n; i++) {       mmax[i][0] = i;       mmin[i][0] = i;     }     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 0; i < n; i++) {         mmin[i][j] = mmin[i][j - 1];         if ((i + (1 << (j - 1)) < n) &&             (yyy(mmin[i + (1 << (j - 1))][j - 1]) > yyy(mmin[i][j - 1])))           mmin[i][j] = mmin[i + (1 << (j - 1))][j - 1];         mmax[i][j] = mmax[i][j - 1];         if ((i + (1 << (j - 1)) < n) &&             (xxx(mmax[i + (1 << (j - 1))][j - 1]) > xxx(mmax[i][j - 1])))           mmax[i][j] = mmax[i + (1 << (j - 1))][j - 1];       }     }     for (int i = 0; i < m; i++) {       cin >> aaa[i] >> bbb[i];     }     for (int i = 0; i < m; i++) {       b = aaa[i];       a = bbb[i];       a--;       b--;       a = (a + 1) % (n / 2);       b = (b + n - 1) % (n / 2);       if (a > b) {         b += n / 2;       }       long long r1 = -(1ll << 60);       int xx = xval(a, b);       int yy;       if (xx < b) {         yy = yval(xx + 1, b);         r1 = yyy(yy) + xxx(xx);       }       yy = yval(a, b);       long long r2 = -(1ll << 60);       if (yy > a) {         xx = xval(a, yy - 1);         r2 = yyy(yy) + xxx(xx);       }       cout << max(r1, r2) << endl;     }     return 0;   }   