func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     register T sum = 0;     register char cc = getchar();     int sym = 1;     while (cc !=  -  && (cc >  9  || cc <  0 )) cc = getchar();     if (cc ==  - ) sym = -1, cc = getchar();     sum = sum * 10 + cc -  0 ;     cc = getchar();     while (cc >=  0  && cc <=  9 ) sum = sum * 10 + cc -  0 , cc = getchar();     return sym * sum;   }   template <typename T>   inline T read(T& a) {     a = read<T>();     return a;   }   template <typename T, typename... Others>   inline void read(T& a, Others&... b) {     a = read(a);     read(b...);   }   int n, m, tp1, tp2, cnt, a[200010], L[200010], M[200010], R[200010],       pre[200010], nxt[200010];   int sta1[200010], sta2[200010], pop1[200010], pop2[200010], buck[200010],       back[200010];   int suf1[200010], suf2[200010], st1[20][200010], st2[20][200010];   set<int> s;   int upper(int x) {     int l = 1, r = tp1;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[sta1[mid]] > x)         l = mid + 1;       else         r = mid - 1;     }     if (!r) return n + 1;     return sta1[r];   }   int lower(int x) {     int l = 1, r = tp2;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[sta2[mid]] < x)         l = mid + 1;       else         r = mid - 1;     }     if (!r) return n + 1;     return sta2[r];   }   int query1(int l, int r) {     int k = log2(r - l + 1);     int ls = st1[k][l], rs = st1[k][r - (1 << k) + 1];     if (back[ls] <= back[rs]) return ls;     return rs;   }   int query2(int l, int r) {     int k = log2(r - l + 1);     int ls = st2[k][l], rs = st2[k][r - (1 << k) + 1];     if (R[ls] <= R[rs]) return ls;     return rs;   }   int main() {     read(n, m);     for (int i = 1; i <= n; i++) read(a[i]);     for (int i = 1; i <= n; i++) {       if (a[i - 1] != a[i])         pre[i] = i - 1;       else         pre[i] = pre[i - 1];     }     for (int i = n; i >= 1; i--) {       if (a[i + 1] != a[i])         nxt[i] = i + 1;       else         nxt[i] = nxt[i + 1];     }     R[0] = n + 1;     for (int i = 1; i <= n; i++) {       if (!pre[i] || nxt[i] == n + 1) continue;       if (1ll * (a[i] - a[pre[i]]) * (a[i] - a[nxt[i]]) > 0) {         cnt += 1;         L[cnt] = pre[i];         M[cnt] = i;         R[cnt] = nxt[i];         if (nxt[i] < R[st2[0][pre[i]]]) st2[0][pre[i]] = cnt;       }     }     s.insert(n + 1);     for (int i = n; i >= 1; i--) {       while (tp1 && a[sta1[tp1]] < a[i]) {         buck[sta1[tp1]] -= 1;         pop1[sta1[tp1]] = i;         if (!buck[sta1[tp1]]) s.insert(sta1[tp1]);         tp1 -= 1;       }       sta1[++tp1] = i;       buck[i] += 1;       while (tp2 && a[sta2[tp2]] > a[i]) {         buck[sta2[tp2]] -= 1;         pop2[sta2[tp2]] = i;         if (!buck[sta2[tp2]]) s.insert(sta2[tp2]);         tp2 -= 1;       }       sta2[++tp2] = i;       buck[i] += 1;       suf1[i] = upper(a[i]);       suf2[i] = lower(a[i]);       back[i] = *s.lower_bound(max(suf1[i], suf2[i]));     }     for (int i = 1; i <= n; i++) st1[0][i] = i;     for (int i = 1; (1 << i) <= n; i++)       for (int j = 1; j + (1 << i) - 1 <= n; j++) {         int ls = st1[i - 1][j], rs = st1[i - 1][j + (1 << (i - 1))];         if (back[ls] <= back[rs])           st1[i][j] = ls;         else           st1[i][j] = rs;         ls = st2[i - 1][j], rs = st2[i - 1][j + (1 << (i - 1))];         if (R[ls] <= R[rs])           st2[i][j] = ls;         else           st2[i][j] = rs;       }     for (int i = 1; i <= m; i++) {       int l, r;       read(l, r);       int mn = query1(l, r);       if (back[mn] <= r) {         int x = pop1[back[mn]], y = pop2[back[mn]];         if (a[mn] < a[back[mn]])           y = suf2[mn];         else           x = suf1[mn];         printf( 4 n%d %d %d %d n , mn, min(x, y), max(x, y), back[mn]);       } else {         int k = query2(l, r);         if (R[k] <= r)           printf( 3 n%d %d %d n , L[k], M[k], R[k]);         else           printf( 0 n n );       }     }     return 0;   }   