func_code_string: #include <bits/stdc++.h>   using namespace std;   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline void read(int &x) {     char c = nc(), b = 1;     for (; !(c >=  0  && c <=  9 ); c = nc()) {       if (c ==  - ) b = -b;     }     for (x = 0; c >=  0  && c <=  9 ; x = x * 10 + c -  0 , c = nc())       ;     x *= b;   }   const int N = 500001;   const int sqN = 708;   int ans[N];   int fre[N];   int v[N];   int block[sqN];   int flag[sqN];   int answer = 0;   vector<int> bl;   struct query {     int l;     int r;     int idx;   } Q[N];   bool comp(query q1, query q2) {     if (q1.l / sqN != q2.l / sqN) {       return q1.l < q2.l;     }     if ((q1.l / sqN) & 1) {       return q1.r < q2.r;     }     return q1.r > q2.r;   }   inline void add(int idx) {     int val = v[idx];     fre[val]++;     if (fre[val] == 1) {       answer++;       block[val / sqN]++;       if (!flag[val / sqN]) {         flag[val / sqN] = 1;         bl.push_back(val / sqN);       }     }     if (fre[val] == 2) {       answer--;       block[val / sqN]--;     }   }   inline void rem(int idx) {     int val = v[idx];     fre[val]--;     if (fre[val] == 1) {       answer++;       block[val / sqN]++;       if (!flag[val / sqN]) {         flag[val / sqN] = 1;         bl.push_back(val / sqN);       }     }     if (fre[val] == 0) {       answer--;       block[val / sqN]--;     }   }   inline int solve() {     if (answer == 0) {       return 0;     }     while (!bl.empty() && block[bl.back()] < 1)       flag[bl.back()] = 0, bl.pop_back();     int i = bl.back();     for (int j = i * sqN; j < i * sqN + sqN; j++) {       if (fre[j] == 1) {         return j;       }     }   }   int main() {     int n;     read(n);     for (int i = 0; i < n; i++) {       read(v[i]);     }     int q, l, r;     read(q);     for (int i = 0; i < q; i++) {       read(l);       read(r);       l--;       r--;       Q[i].l = l;       Q[i].r = r;       Q[i].idx = i;     }     sort(Q, Q + q, comp);     l = 0, r = -1;     for (int i = 0; i < q; i++) {       int L = Q[i].l;       int R = Q[i].r;       while (l < L) {         rem(l);         l++;       }       while (l > L) {         l--;         add(l);       }       while (r < R) {         r++;         add(r);       }       while (r > R) {         rem(r);         r--;       }       ans[Q[i].idx] = solve();     }     for (int i = 0; i < q; i++) {       printf( %d n , ans[i]);     }     return 0;   }   