#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+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IG1heG4gPSAxZTUsIG1heGsgPSAxZTYgKyAxOwppbnQgcm9vdFttYXhuXSwgTFsxNiAqIG1heG5dLCBSWzE2ICogbWF4bl0sIHN1bVsxNiAqIG1heG5dOwppbnQgcnQgPSAxLCBzeiA9IDE7CmludCBscG9zW21heGtdOwoKaW50IGNvcHkoaW50IHYsIGludCAmdSkKewogICAgTFtzel0gPSBMW3ZdOwogICAgUltzel0gPSBSW3ZdOwogICAgc3VtW3N6XSA9IHN1bVt2XTsKICAgIHJldHVybiB1ID0gc3orKzsKfQoKdm9pZCBtYWtlX3Jvb3QoKQp7CiAgICBjb3B5KHJvb3RbcnQgLSAxXSwgcm9vdFtydF0pOwogICAgcnQrKzsKfQoKdm9pZCBhZGQoaW50IHBvcywgaW50IHgsIGludCB2ID0gcm9vdFtydCAtIDFdLCBpbnQgbCA9IDAsIGludCByID0gbWF4bikKewoJc3VtW3ZdICs9IHg7CiAgICBpZihyIC0gbCA9PSAxKQogICAgICAgIHJldHVybjsKICAgIGludCBtID0gKGwgKyByKSAvIDI7CiAgICBpZihwb3MgPCBtKQogICAgICAgIGFkZChwb3MsIHgsIGNvcHkoTFt2XSwgTFt2XSksIGwsIG0pOwogICAgZWxzZQogICAgICAgIGFkZChwb3MsIHgsIGNvcHkoUlt2XSwgUlt2XSksIG0sIHIpOwp9CgppbnQgZ2V0KGludCBhLCBpbnQgYiwgaW50IHYsIGludCBsID0gMCwgaW50IHIgPSBtYXhuKQp7CiAgICBpZihhIDw9IGwgJiYgciA8PSBiKQogICAgICAgIHJldHVybiBzdW1bdl07CiAgICBpZihyIDw9IGEgfHwgYiA8PSBsKQogICAgICAgIHJldHVybiAwOwogICAgaW50IG0gPSAobCArIHIpIC8gMjsKICAgIHJldHVybiBnZXQoYSwgYiwgTFt2XSwgbCwgbSkgKyBnZXQoYSwgYiwgUlt2XSwgbSwgcik7Cn0KCmludCBtYWluKCkKIHsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGludCBuOwogICAgY2luID4+IG47CiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKykKICAgIHsKICAgICAgICBpbnQgdDsKICAgICAgICBjaW4gPj4gdDsKICAgICAgICBtYWtlX3Jvb3QoKTsKICAgICAgICBhZGQobHBvc1t0XSwgLTEpOwogICAgICAgIGxwb3NbdF0gPSBpOwogICAgICAgIGFkZChscG9zW3RdLCAxKTsKICAgIH0KCiAgICBpbnQgcSwgbCwgcjsKICAgIGNpbiA+PiBxOwogICAgd2hpbGUocS0tKQogICAgewogICAgICAgIGNpbiA+PiBsID4+IHI7CiAgICAgICAgY291dCA8PCBnZXQobCwgciArIDEsIHJvb3Rbcl0pIDw8ICJcbiI7CiAgICB9CiAgICByZXR1cm4gMDsKIH0K