func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   inline long long rd() {     long long x = 0;     char c = getchar();     int neg = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * neg;   }   int N, Q, pre[maxn], A[maxn], tmp[maxn], ans[maxn];   pair<int, int> mn[maxn << 2];   struct Node {     int l, r, i;   } que[maxn];   inline bool cmp(Node a, Node b) { return a.r < b.r; };   inline void update(int p) { mn[p] = min(mn[p << 1], mn[p << 1 | 1]); }   void change(int p, int l, int r, int x, int y) {     if (l == r)       mn[p] = make_pair(y, x);     else {       int m = l + r >> 1;       if (x <= m)         change(p << 1, l, m, x, y);       else         change(p << 1 | 1, m + 1, r, x, y);       update(p);     }   }   pair<int, int> query(int p, int l, int r, int x, int y) {     if (x <= l && r <= y) return mn[p];     int m = l + r >> 1;     pair<int, int> re = make_pair(N + 1, 0);     if (x <= m) re = query(p << 1, l, m, x, y);     if (y >= m + 1) re = min(re, query(p << 1 | 1, m + 1, r, x, y));     return re;   }   int main() {     int i, j, k;     N = rd();     for (i = 1; i <= N; i++) {       A[i] = rd();       pre[i] = tmp[A[i]], tmp[A[i]] = i;     }     Q = rd();     for (i = 1; i <= Q; i++) {       que[i].l = rd(), que[i].r = rd(), que[i].i = i;     }     sort(que + 1, que + Q + 1, cmp);     memset(mn, 127, sizeof(mn));     for (i = 1, j = 1; i <= Q; i++) {       for (; j <= que[i].r && j <= N; j++) {         if (pre[j]) change(1, 1, N, pre[j], N + 1);         change(1, 1, N, j, pre[j]);       }       pair<int, int> re = query(1, 1, N, que[i].l, que[i].r);       if (re.first < que[i].l) ans[que[i].i] = A[re.second];     }     for (i = 1; i <= Q; i++) printf( %d n , ans[i]);     return 0;   }   