func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MX = 5e5 + 100, INF = 1e9;   int N, M, X[MX], cnt;   map<int, int> mp;   struct Seg {     int z;     int l, r;     Seg *L, *R;     void update(int x) { z = min(z, x); }     void pushdown() { L->update(z), R->update(z); }     void init(int a, int b);     void Min(int a, int b, int x);     int ask(int a);   } T[MX << 1], *Cnt = T;   Seg* New() { return ++Cnt; }   void Seg::init(int a, int b) {     l = a, r = b, z = INF;     if (l == r) return;     int m = (l + r) >> 1;     L = New(), L->init(l, m);     R = New(), R->init(m + 1, r);   }   void Seg::Min(int a, int b, int x) {     if (a <= l && r <= b) {       update(x);       return;     }     pushdown();     if (a <= L->r) L->Min(a, b, x);     if (b >= R->l) R->Min(a, b, x);   }   int Seg::ask(int a) {     if (l == r) return z;     pushdown();     if (a <= L->r)       return L->ask(a);     else       return R->ask(a);   }   struct Query {     int id, l, nx;   } Q[MX];   int H[MX], qc;   void add(int id, int l, int r) {     Q[++qc].id = id, Q[qc].l = l, Q[qc].nx = H[r], H[r] = qc;   }   int ans[MX];   int A[MX];   void Solve() {     for (int i = (1); i <= (N); ++i) {       int c = X[i];       if (A[c]) {         int delta = i - A[c];         T->Min(1, A[c], delta);       }       A[c] = i;       for (int j = H[i]; j; j = Q[j].nx) ans[Q[j].id] = T->ask(Q[j].l);     }   }   int main() {     scanf( %d%d , &N, &M);     int x;     for (int i = (1); i <= (N); ++i) {       scanf( %d , &x);       if (!mp.count(x)) mp[x] = ++cnt;       X[i] = mp[x];     }     T->init(1, N);     int l, r;     for (int i = (1); i <= (M); ++i) {       scanf( %d%d , &l, &r);       add(i, l, r);     }     Solve();     for (int i = (1); i <= (M); ++i)       printf( %d n , (ans[i] == INF ? -1 : ans[i]));     return 0;   }   