func_code_string: #include <bits/stdc++.h>   using namespace std;   void Read(int &x) {     static char c;     while (!isdigit(c = getchar()))       ;     x = (c ^ 48);     while (isdigit(c = getchar())) x = x * 10 + (c ^ 48);     return;   }   void Print(int x, char end) {     static int i;     for (i = 1; i * 10LL <= x; i *= 10)       ;     for (; i; i /= 10) putchar(x / i % 10 | 48);     putchar(end);     return;   }   inline int mmin(int a, int b) { return a < b ? a : b; }   inline int mmax(int a, int b) { return a > b ? a : b; }   inline void Swap(int &a, int &b) {     static int t;     t = a, a = b, b = t;     return;   }   set<int> rm;   int n, q, a[(200005)], pre[(200005)], nxt[(200005)], gd[(200005)], b2[(200005)],       b3[(200005)], b4[(200005)], cnt[(200005)], stk1[(200005)], p1[(200005)],       tot1, stk2[(200005)], p2[(200005)], tot2, Log2[(200005)];   pair<int, int> maxa[20][(200005)], mina[20][(200005)], st[20][(200005)];   void init_ST_A() {     int i, j;     Log2[1] = 0;     for (i = 2; i <= n; ++i) Log2[i] = Log2[i >> 1] + 1;     for (i = 1; i <= n; ++i) {       mina[0][i].first = a[i], mina[0][i].second = i;       maxa[0][i] = mina[0][i];     }     for (i = 1; (1 << i) <= n; ++i)       for (j = 1; j + (1 << i) - 1 <= n; ++j) {         mina[i][j] = min(mina[i - 1][j], mina[i - 1][j + (1 << (i - 1))]);         maxa[i][j] = max(maxa[i - 1][j], maxa[i - 1][j + (1 << (i - 1))]);       }     return;   }   void init_ST_B() {     int i, j;     for (i = 1; i <= n; ++i) st[0][i].first = b4[i], st[0][i].second = i;     for (i = 1; (1 << i) <= n; ++i)       for (j = 1; j + (1 << i) - 1 <= n; ++j)         st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);     return;   }   inline int AskMinA(int l, int r) {     int k = Log2[r - l + 1];     return min(mina[k][l], mina[k][r - (1 << k) + 1]).second;   }   inline int AskMaxA(int l, int r) {     int k = Log2[r - l + 1];     return max(maxa[k][l], maxa[k][r - (1 << k) + 1]).second;   }   inline pair<int, int> AskMinB(int l, int r) {     int k = Log2[r - l + 1];     return min(st[k][l], st[k][r - (1 << k) + 1]);   }   int main() {     int L, R, pt;     pair<int, int> p;     Read(n);     Read(q);     for (int i = 1; i <= n; ++i) Read(a[i]);     init_ST_A();     pt = 0;     pre[0] = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] != a[i - 1]) pt = i - 1;       pre[i] = pt;     }     pt = n + 1;     nxt[n + 1] = n + 1;     for (int i = n; i; --i) {       if (a[i] != a[i + 1]) pt = i + 1;       nxt[i] = pt;     }     gd[n + 1] = gd[n] = n + 1;     for (int i = n - 1; i > 1; --i)       gd[i] = (pre[i] && nxt[i] != n + 1 &&                ((a[pre[i]] < a[i] && a[i] > a[nxt[i]]) ||                 (a[pre[i]] > a[i] && a[i] < a[nxt[i]])))                   ? (i)                   : (gd[i + 1]);     stk1[0] = stk2[0] = n + 1;     rm.insert(n + 1);     for (int i = n; i; --i) {       while (tot1 && a[i] < a[stk1[tot1]]) {         if ((++cnt[stk1[tot1]]) == 2) rm.insert(stk1[tot1]);         --tot1;       }       stk1[++tot1] = i;       p1[tot1] =           ((a[stk1[tot1 - 1]] == a[i]) ? (p1[tot1 - 1]) : (stk1[tot1 - 1]));       while (tot2 && a[i] > a[stk2[tot2]]) {         if ((++cnt[stk2[tot2]] == 2)) rm.insert(stk2[tot2]);         --tot2;       }       stk2[++tot2] = i;       p2[tot2] =           ((a[stk2[tot2 - 1]] == a[i]) ? (p2[tot2 - 1]) : (stk2[tot2 - 1]));       b4[i] = *rm.lower_bound(mmax(p1[tot1], p2[tot2]));       if (b4[i] != n + 1) {         b2[i] = AskMinA(i, b4[i]);         b3[i] = AskMaxA(i, b4[i]);         if (b2[i] > b3[i]) Swap(b2[i], b3[i]);       }     }     init_ST_B();     while (q--) {       Read(L);       Read(R);       p = AskMinB(L, R);       if (p.first <= R) {         Print(4,   n );         Print(p.second,    );         Print(b2[p.second],    );         Print(b3[p.second],    );         Print(p.first,   n );       } else {         pt = gd[nxt[L]];         if (nxt[pt] > R) {           Print(0,   n );           putchar(  n );         } else {           Print(3,   n );           Print(pre[pt],    );           Print(pt,    );           Print(nxt[pt],   n );         }       }     }     return 0;   }   