func_code_string: #include <bits/stdc++.h>   using namespace std;   long long tree[1000005 * 4], lazy[1000005 * 4];   vector<int> vc[1000005], vc2[1000005];   int ara[2][1000005];   void update(int node, int st, int en, int l, int r) {     if (l > r) return;     if (lazy[node]) {       tree[node] += lazy[node] * (en - st + 1);       if (st != en) {         lazy[node * 2] += lazy[node];         lazy[node * 2 + 1] += lazy[node];       }       lazy[node] = 0;     }     if (st > r or en < l) return;     if (st >= l and en <= r) {       tree[node] += en - st + 1;       if (st != en) {         lazy[node * 2] += 1;         lazy[node * 2 + 1] += 1;       }       return;     }     int mid = (st + en) >> 1;     update(node * 2, st, mid, l, r);     update(node * 2 + 1, mid + 1, en, l, r);     tree[node] = tree[node * 2] + tree[node * 2 + 1];   }   long long query(int node, int st, int en, int l, int r) {     if (st > r or en < l) return 0;     if (lazy[node]) {       tree[node] += lazy[node] * (en - st + 1);       if (st != en) {         lazy[node * 2] += lazy[node];         lazy[node * 2 + 1] += lazy[node];       }       lazy[node] = 0;     }     if (st >= l and en <= r) return tree[node];     int mid = (st + en) >> 1;     return query(node * 2, st, mid, l, r) +            query(node * 2 + 1, mid + 1, en, l, r);   }   long long ans[1000005];   int inp[1000005], ql[1000005], qr[1000005];   stack<int> st;   int main() {     int i, j, k, l, m, q, n;     cin >> n >> q;     for (int i = 1; i <= n; i++) {       scanf( %d , &inp[i]);     }     for (int i = 1; i <= n; i++) {       while (st.size()) {         int v = st.top();         if (inp[v] < inp[i]) {           ara[1][v] = i - 1;           st.pop();         } else           break;       }       st.push(i);     }     while (st.size()) {       int v = st.top();       st.pop();       ara[1][v] = n;     }     for (int i = n; i >= 1; i--) {       while (st.size()) {         int v = st.top();         if (inp[v] < inp[i]) {           ara[0][v] = i + 1;           st.pop();         } else           break;       }       st.push(i);     }     while (st.size()) {       int v = st.top();       st.pop();       ara[0][v] = 1;     }     for (int i = 1; i <= q; i++) {       scanf( %d , &ql[i]);     }     for (int i = 1; i <= q; i++) {       scanf( %d , &qr[i]);       vc[qr[i]].push_back(i);       vc2[ql[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       update(1, 1, n, ara[0][i], i - 1);       for (int j = 0; j < vc[i].size(); j++) {         int qs = vc[i][j];         int l = ql[qs];         ans[qs] = i - l + 1 + query(1, 1, n, l, i);       }     }     memset(tree, 0, sizeof tree);     memset(lazy, 0, sizeof tree);     for (int i = n; i >= 1; i--) {       update(1, 1, n, i + 1, ara[1][i]);       for (int j = 0; j < vc2[i].size(); j++) {         int qs = vc2[i][j];         int r = qr[qs];         ans[qs] += query(1, 1, n, i + 1, r);       }     }     for (int i = 1; i <= q; i++) {       printf( %lld  , ans[i]);     }   }   