#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int id[N], pre[N], aa[N], ll[N];
int cc[2][N], dd[N];
int n;
void update(int x, int v, int id = 0) {
  if (x == 0) return;
  while (x <= n) cc[id][x] += v, x += x & -x;
}
int query(int x, int id = 0) {
  int ans = 0;
  while (x) ans += cc[id][x], x -= x & -x;
  return ans;
}
struct PP {
  int l, r, id;
  bool operator<(const PP& th) const { return r < th.r; }
} pp[N];
int ans[N];
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &aa[i]);
    int q;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) scanf("%d%d", &pp[i].l, &pp[i].r), pp[i].id = i;
    sort(pp, pp + q);
    memset(id, 0, sizeof(id));
    memset(pre, 0, sizeof(pre));
    memset(cc, 0, sizeof(cc));
    for (int i = 1, j = 0; i <= n; i++) {
      pre[i] = id[aa[i]];
      id[aa[i]] = i;
      update(pre[i], -1);
      update(i, 1);
      if (pre[pre[i]] == 0 || i - pre[i] == pre[i] - pre[pre[i]])
        ll[i] = ll[pre[i]];
      else
        ll[i] = pre[i];
      update(pre[ll[i]], -1, 1);
      update(i, 1, 1);
      update(pre[ll[pre[i]]], 1, 1);
      update(pre[i], -1, 1);
      while (j < q && pp[j].r == i) {
        ans[pp[j].id] = query(pp[j].r) - query(pp[j].l - 1) +
                        ((query(pp[j].r, 1) - query(pp[j].l - 1, 1)) == 0);
        j++;
      }
    }
    for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
