func_code_string: #include <bits/stdc++.h>   using namespace std;   int a[200010];   struct seg {     int val, idx;   } tree1[600010], tree2[600010];   void build(int node, int s, int e) {     if (s > e) return;     if (s == e) {       tree1[node].val = a[s];       tree1[node].idx = s;       tree2[node].val = a[s];       tree2[node].idx = s;       return;     }     int mid = (s + e) / 2;     build(2 * node, s, mid);     build(2 * node + 1, mid + 1, e);     if (tree1[2 * node].val > tree1[2 * node + 1].val)       tree1[node].idx = tree1[2 * node + 1].idx;     else       tree1[node].idx = tree1[2 * node].idx;     if (tree2[2 * node].val > tree2[2 * node + 1].val)       tree2[node].idx = tree2[2 * node].idx;     else       tree2[node].idx = tree2[2 * node + 1].idx;     tree1[node].val = min(tree1[2 * node].val, tree1[2 * node + 1].val);     tree2[node].val = max(tree2[2 * node].val, tree2[2 * node + 1].val);   }   seg query1(int node, int s, int end, int l, int r) {     if (s > end || s > r || end < l) {       seg temp;       temp.val = 1000000000;       temp.idx = -1;       return temp;     }     if (s >= l && end <= r) return tree1[node];     seg res1 = query1(2 * node, s, (s + end) / 2, l, r);     seg res2 = query1(2 * node + 1, (s + end) / 2 + 1, end, l, r);     seg res;     if (res1.val < res2.val) {       res.val = res1.val;       res.idx = res1.idx;     } else {       res.val = res2.val;       res.idx = res2.idx;     }     return res;   }   seg query2(int node, int s, int end, int l, int r) {     if (s > end || s > r || end < l) {       seg temp;       temp.val = -1000000000;       temp.idx = -1;       return temp;     }     if (s >= l && end <= r) return tree2[node];     seg res1 = query2(2 * node, s, (s + end) / 2, l, r);     seg res2 = query2(2 * node + 1, (s + end) / 2 + 1, end, l, r);     seg res;     if (res1.val > res2.val) {       res.val = res1.val;       res.idx = res1.idx;     } else {       res.val = res2.val;       res.idx = res2.idx;     }     return res;   }   int main() {     int n;     cin >> n;     int q;     cin >> q;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     build(1, 0, n - 1);     while (q--) {       int l, r, x;       scanf( %d %d %d , &l, &r, &x);       l--;       r--;       seg mx = query1(1, 0, n - 1, l, r);       seg mi = query2(1, 0, n - 1, l, r);       if (mx.val == x && mi.val == x) {         printf( -1 n );       } else if (mx.val == x) {         printf( %d n , mi.idx + 1);       } else         printf( %d n , mx.idx + 1);     }     return 0;   }   