func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, logN = 20;   const int M = 350;   int d[N], h[N], floorlog[N << 1];   long long D[N], F1[N], F2[N], lft[N], rgt[N], total = 0;   map<pair<int, int>, long long> st;   vector<pair<int, int> > queries, q;   pair<int, int> rmq1[logN][N], rmq2[logN][N];   int max(int i, int j, long long f[]) { return f[i] > f[j] ? i : j; }   pair<int, int> merge(pair<int, int>& x, pair<int, int>& y, long long f[]) {     if (f[x.first] > f[y.first]) {       return {x.first, max(x.second, y.first, f)};     }     if (x.first == y.first) {       return {y.first, max(x.second, y.second, f)};     }     return {y.first, max(x.first, y.second, f)};   }   void make_rmq(long long f[], pair<int, int> rmq[][N], int n) {     for (int i = n; i >= 1; i--) {       rmq[0][i] = {i, 0};       for (int j = 1; i + (1 << j) - 1 <= n; j++) {         rmq[j][i] = merge(rmq[j - 1][i], rmq[j - 1][i + (1 << (j - 1))], f);       }     }   }   pair<int, int> get(int i, int j, pair<int, int> rmq[][N], long long f[]) {     int k = floorlog[j - i + 1];     return merge(rmq[k][i], rmq[k][j - (1 << k) + 1], f);   }   long long query(int l, int r) {     pair<int, int> P = get(l, r, rmq1, F1);     pair<int, int> Q = get(l, r, rmq2, F2);     long long mx = 0;     if (P.first != Q.first) mx = max(mx, F1[P.first] + F2[Q.first]);     if (P.second != Q.first) mx = max(mx, F1[P.second] + F2[Q.first]);     if (P.first != Q.second) mx = max(mx, F1[P.first] + F2[Q.second]);     if (P.second != Q.second) mx = max(mx, F1[P.second] + F2[Q.second]);     return mx;   }   int main() {     for (int i = 0; (1 << i) < N; i++)       for (int j = (1 << i); j < (1 << (i + 1)); j++) floorlog[j] = i;     int n, m;     scanf( %d , &(n));     scanf( %d , &(m));     for (int i = 1; i <= n; i++) {       D[i] = D[i - 1] + d[i - 1];       scanf( %d , &(d[i]));       total += d[i];     }     for (int i = 1; i <= n; i++) {       scanf( %d , &(h[i]));       F1[i] = D[i] + 2 * h[i];       F2[i] = -D[i] + 2 * h[i];       rgt[i] = max(rgt[i - 1], D[i] + 2 * h[i]);     }     for (int i = n; i >= 1; i--) {       lft[i] = max(lft[i + 1], total - D[i] + 2 * h[i]);     }     F1[0] = -1e18;     F2[0] = -1e18;     make_rmq(F1, rmq1, n);     make_rmq(F2, rmq2, n);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d , &(a));       scanf( %d , &(b));       q.push_back({a, b});       if (a > b) {         int l = b + 1, r = a - 1;         printf( %lld n , query(l, r));       } else {         long long ans = 0;         if (b != n && a != 1) ans = max(ans, lft[b + 1] + rgt[a - 1]);         if (b != n) ans = max(ans, query(b + 1, n));         if (a != 1) ans = max(ans, query(1, a - 1));         printf( %lld n , ans);       }     }   }   