func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   inline int read() {     int x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) f |= (c ==  - ), c = getchar();     while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     return f ? -x : x;   }   int n, m, t;   int sq[500005], a[500005], pos[500005], cnt[500005], ans[500005], st[500005],       top;   struct node {     int l, r, id;   } q[500005];   int nowx, nowy;   inline bool operator<(node x, node y) {     return (sq[x.l] ^ sq[y.l]) ? x.l < y.l                                : ((sq[x.l] & 1) ? x.r < y.r : x.r > y.r);   }   inline void Add(int x) {     if (cnt[a[x]] == 1) {       st[pos[a[x]]] = st[top];       pos[st[top]] = pos[a[x]];       pos[a[x]] = st[top--] = 0;     }     cnt[a[x]]++;     if (cnt[a[x]] == 1) st[++top] = a[x], pos[a[x]] = top;   }   inline void Delete(int x) {     if (cnt[a[x]] == 1) {       st[pos[a[x]]] = st[top];       pos[st[top]] = pos[a[x]];       pos[a[x]] = st[top--] = 0;     }     cnt[a[x]]--;     if (cnt[a[x]] == 1) st[++top] = a[x], pos[a[x]] = top;   }   int main() {     n = read(), t = sqrt(n);     for (register int i = 1; i <= n; ++i) a[i] = read(), sq[i] = i / t;     m = read();     for (register int i = 1; i <= m; ++i)       q[i].l = read(), q[i].r = read(), q[i].id = i;     sort(q + 1, q + m + 1);     nowx = 1, nowy = 0;     for (register int i = 1; i <= m; ++i) {       while (nowx < q[i].l) Delete(nowx++);       while (nowx > q[i].l) Add(--nowx);       while (nowy > q[i].r) Delete(nowy--);       while (nowy < q[i].r) Add(++nowy);       ans[q[i].id] = st[top];     }     for (register int i = 1; i <= m; ++i) printf( %d n , ans[i]);     return 0;   }   