#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int root[maxn], L[16 * maxn], R[16 * maxn], sum[16 * maxn];
int rt = 1, sz = 1;
int copy(int v, int &u)
{
L[sz] = L[v];
R[sz] = R[v];
sum[sz] = sum[v];
return u = sz++;
}
void make_root()
{
copy(root[rt - 1], root[rt]);
rt++;
}
void add(int pos, int x, int v = root[rt - 1], int l = 0, int r = maxn)
{
if(r - l == 1)
{
sum[v] += x;
return;
}
int m = (l + r) / 2;
if(pos < m)
add(pos, x, copy(L[v], L[v]), l, m);
else
add(pos, x, copy(R[v], R[v]), m, r);
sum[v] = sum[L[v]] + sum[R[v]];
}
int get(int a, int b, int v = root[rt - 1], int l = 0, int r = maxn)
{
if(a <= l && r <= b)
return sum[v];
if(r <= a || b <= l)
return 0;
int m = (l + r) / 2;
return get(a, b, L[v], l, m) + get(a, b, R[v], m, r);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
map<int, int> lpos;
for(int i = 1; i <= n; i++)
{
int t;
cin >> t;
make_root();
add(lpos[t], -1);
lpos[t] = i;
add(lpos[t], 1);
}
int q, l, r;
cin >> q;
while(q--)
{
cin >> l >> r;
cout << get(l, r + 1, root[r]) << "\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIApjb25zdCBpbnQgbWF4biA9IDFlNTsKaW50IHJvb3RbbWF4bl0sIExbMTYgKiBtYXhuXSwgUlsxNiAqIG1heG5dLCBzdW1bMTYgKiBtYXhuXTsKaW50IHJ0ID0gMSwgc3ogPSAxOwogCmludCBjb3B5KGludCB2LCBpbnQgJnUpCnsKICAgIExbc3pdID0gTFt2XTsKICAgIFJbc3pdID0gUlt2XTsKICAgIHN1bVtzel0gPSBzdW1bdl07CiAgICByZXR1cm4gdSA9IHN6Kys7Cn0KIAp2b2lkIG1ha2Vfcm9vdCgpCnsKICAgIGNvcHkocm9vdFtydCAtIDFdLCByb290W3J0XSk7CiAgICBydCsrOwp9CiAKdm9pZCBhZGQoaW50IHBvcywgaW50IHgsIGludCB2ID0gcm9vdFtydCAtIDFdLCBpbnQgbCA9IDAsIGludCByID0gbWF4bikKewogICAgaWYociAtIGwgPT0gMSkKICAgIHsKICAgICAgICBzdW1bdl0gKz0geDsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBpbnQgbSA9IChsICsgcikgLyAyOwogICAgaWYocG9zIDwgbSkKICAgICAgICBhZGQocG9zLCB4LCBjb3B5KExbdl0sIExbdl0pLCBsLCBtKTsKICAgIGVsc2UKICAgICAgICBhZGQocG9zLCB4LCBjb3B5KFJbdl0sIFJbdl0pLCBtLCByKTsKICAgIHN1bVt2XSA9IHN1bVtMW3ZdXSArIHN1bVtSW3ZdXTsKfQogCmludCBnZXQoaW50IGEsIGludCBiLCBpbnQgdiA9IHJvb3RbcnQgLSAxXSwgaW50IGwgPSAwLCBpbnQgciA9IG1heG4pCnsKICAgIGlmKGEgPD0gbCAmJiByIDw9IGIpCiAgICAgICAgcmV0dXJuIHN1bVt2XTsKICAgIGlmKHIgPD0gYSB8fCBiIDw9IGwpCiAgICAgICAgcmV0dXJuIDA7CiAgICBpbnQgbSA9IChsICsgcikgLyAyOwogICAgcmV0dXJuIGdldChhLCBiLCBMW3ZdLCBsLCBtKSArIGdldChhLCBiLCBSW3ZdLCBtLCByKTsKfQogCmludCBtYWluKCkKIHsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGludCBuOwogICAgY2luID4+IG47CiAgICBtYXA8aW50LCBpbnQ+IGxwb3M7CiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKykKICAgIHsKICAgICAgICBpbnQgdDsKICAgICAgICBjaW4gPj4gdDsKICAgICAgICBtYWtlX3Jvb3QoKTsKICAgICAgICBhZGQobHBvc1t0XSwgLTEpOwogICAgICAgIGxwb3NbdF0gPSBpOwogICAgICAgIGFkZChscG9zW3RdLCAxKTsKICAgIH0KIAogICAgaW50IHEsIGwsIHI7CiAgICBjaW4gPj4gcTsKICAgIHdoaWxlKHEtLSkKICAgIHsKICAgICAgICBjaW4gPj4gbCA+PiByOwogICAgICAgIGNvdXQgPDwgZ2V0KGwsIHIgKyAxLCByb290W3JdKSA8PCAiXG4iOwogICAgfQogICAgcmV0dXJuIDA7CiB9