#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5, maxk = 1e6 + 1;
int root[maxn], L[16 * maxn], R[16 * maxn], sum[16 * maxn];
int rt = 1, sz = 1;
int lpos[maxk];
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)
{
sum[v] += x;
if(r - l == 1)
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);
}
int get(int a, int b, int v, 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;
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+CiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIApjb25zdCBpbnQgbWF4biA9IDFlNSwgbWF4ayA9IDFlNiArIDE7CmludCByb290W21heG5dLCBMWzE2ICogbWF4bl0sIFJbMTYgKiBtYXhuXSwgc3VtWzE2ICogbWF4bl07CmludCBydCA9IDEsIHN6ID0gMTsKaW50IGxwb3NbbWF4a107CiAKaW50IGNvcHkoaW50IHYsIGludCAmdSkKewogICAgTFtzel0gPSBMW3ZdOwogICAgUltzel0gPSBSW3ZdOwogICAgc3VtW3N6XSA9IHN1bVt2XTsKICAgIHJldHVybiB1ID0gc3orKzsKfQogCnZvaWQgbWFrZV9yb290KCkKewogICAgY29weShyb290W3J0IC0gMV0sIHJvb3RbcnRdKTsKICAgIHJ0Kys7Cn0KIAp2b2lkIGFkZChpbnQgcG9zLCBpbnQgeCwgaW50IHYgPSByb290W3J0IC0gMV0sIGludCBsID0gMCwgaW50IHIgPSBtYXhuKQp7CglzdW1bdl0gKz0geDsKICAgIGlmKHIgLSBsID09IDEpCiAgICAgICAgcmV0dXJuOwogICAgaW50IG0gPSAobCArIHIpIC8gMjsKICAgIGlmKHBvcyA8IG0pCiAgICAgICAgYWRkKHBvcywgeCwgY29weShMW3ZdLCBMW3ZdKSwgbCwgbSk7CiAgICBlbHNlCiAgICAgICAgYWRkKHBvcywgeCwgY29weShSW3ZdLCBSW3ZdKSwgbSwgcik7Cn0KIAppbnQgZ2V0KGludCBhLCBpbnQgYiwgaW50IHYsIGludCBsID0gMCwgaW50IHIgPSBtYXhuKQp7CiAgICBpZihhIDw9IGwgJiYgciA8PSBiKQogICAgICAgIHJldHVybiBzdW1bdl07CiAgICBpZihyIDw9IGEgfHwgYiA8PSBsKQogICAgICAgIHJldHVybiAwOwogICAgaW50IG0gPSAobCArIHIpIC8gMjsKICAgIHJldHVybiBnZXQoYSwgYiwgTFt2XSwgbCwgbSkgKyBnZXQoYSwgYiwgUlt2XSwgbSwgcik7Cn0KIAppbnQgbWFpbigpCiB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7CiAgICBpbnQgbjsKICAgIGNpbiA+PiBuOwogICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspCiAgICB7CiAgICAgICAgaW50IHQ7CiAgICAgICAgY2luID4+IHQ7CiAgICAgICAgbWFrZV9yb290KCk7CiAgICAgICAgYWRkKGxwb3NbdF0sIC0xKTsKICAgICAgICBscG9zW3RdID0gaTsKICAgICAgICBhZGQobHBvc1t0XSwgMSk7CiAgICB9CiAKICAgIGludCBxLCBsLCByOwogICAgY2luID4+IHE7CiAgICB3aGlsZShxLS0pCiAgICB7CiAgICAgICAgY2luID4+IGwgPj4gcjsKICAgICAgICBjb3V0IDw8IGdldChsLCByICsgMSwgcm9vdFtyXSkgPDwgIlxuIjsKICAgIH0KICAgIHJldHVybiAwOwogfQ==