func_code_string: #include <bits/stdc++.h>   using namespace std;   const int Maxn = 100020;   int n, q;   int a[Maxn];   int pre[Maxn], fin[Maxn], rel[Maxn];   int tree[Maxn << 2];   vector<int> V;   int getid(int x) { return lower_bound(V.begin(), V.end(), x) - V.begin() + 1; }   void add(int tar, int w, int l, int r, int x) {     if (l == r) {       tree[x] = max(tree[x], w);       return;     }     int mid = (l + r) >> 1;     if (tar <= mid)       add(tar, w, l, mid, x << 1);     else       add(tar, w, mid + 1, r, x << 1 | 1);     tree[x] = max(tree[x << 1], tree[x << 1 | 1]);   }   int query(int L, int R, int l, int r, int x) {     if (L <= l && R >= r) return tree[x];     int mid = (l + r) >> 1;     int ret = 0;     if (L <= mid) ret = max(ret, query(L, R, l, mid, x << 1));     if (R > mid) ret = max(ret, query(L, R, mid + 1, r, x << 1 | 1));     return ret;   }   void cal(int *a, int *b, int flag = 0) {     memset(tree, 0, sizeof(tree));     for (int i = 1; i <= n; i++) {       if (flag)         b[i] = query(a[i], V.size(), 1, V.size(), 1);       else {         b[i] = query(a[i] + 1, V.size(), 1, V.size(), 1);       }       add(a[i], i, 1, V.size(), 1);     }   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i < n; i++) a[i] = abs(a[i + 1] - a[i]);     n--;     for (int i = 1; i <= n; i++) V.push_back(a[i]);     sort(V.begin(), V.end());     V.erase(unique(V.begin(), V.end()), V.end());     for (int i = 1; i <= n; i++) a[i] = getid(a[i]);     cal(a, pre);     reverse(a + 1, a + n + 1);     cal(a, fin, 1);     reverse(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) rel[i] = n + 1 - fin[n + 1 - i];     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       r--;       long long ans = 0;       for (int j = l; j <= r; j++) {         long long L = j - max(l - 1, pre[j]);         long long R = min(r + 1, rel[j]) - j;         ans += L * R * V[a[j] - 1];       }       printf( %lld n , ans);     }   }   