#include <bits/stdc++.h>
using namespace std;
int a[200005];
struct val {
  int l;
  int r;
  int i;
} q[200005];
int sq;
int mp[200005];
deque<int> s[200005];
deque<int> w[200005];
int ok[200005];
int ans[200005];
bool comp(val a, val b) {
  if (a.l / sq != b.l / sq)
    return a.l / sq < b.l / sq;
  else
    return a.r < b.r;
}
int main() {
  int n;
  scanf("%d", &n);
  sq = sqrt(n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int qu;
  scanf("%d", &qu);
  int l, r;
  for (int i = 1; i <= qu; i++) {
    scanf("%d %d", &l, &r);
    q[i].l = l;
    q[i].r = r;
    q[i].i = i;
  }
  sort(q + 1, q + qu + 1, comp);
  l = q[1].l;
  r = l - 1;
  int cnt = 0;
  int all = 0;
  for (int i = 1; i <= qu; i++) {
    while (r < q[i].r) {
      r++;
      mp[a[r]]++;
      if (mp[a[r]] == 1) cnt++;
      all -= (ok[a[r]] == 0) && !(s[a[r]].empty());
      if (!(s[a[r]].empty())) {
        if (!w[a[r]].empty())
          ok[a[r]] += (r - s[a[r]].back()) != w[a[r]].back();
        w[a[r]].push_back(r - s[a[r]].back());
      }
      s[a[r]].push_back(r);
      all += (ok[a[r]] == 0) && !(s[a[r]].empty());
    }
    while (l > q[i].l) {
      l--;
      mp[a[l]]++;
      if (mp[a[l]] == 1) cnt++;
      all -= (ok[a[l]] == 0) && !(s[a[l]].empty());
      if (!s[a[l]].empty()) {
        if (!w[a[l]].empty())
          ok[a[l]] += (s[a[l]].front() - l) != w[a[l]].front();
        w[a[l]].push_front(s[a[l]].front() - l);
      }
      s[a[l]].push_front(l);
      all += (ok[a[l]] == 0) && !(s[a[l]].empty());
    }
    while (l < q[i].l) {
      mp[a[l]]--;
      if (mp[a[l]] == 0) cnt--;
      all -= (ok[a[l]] == 0) && !(s[a[l]].empty());
      s[a[l]].pop_front();
      if (s[a[l]].empty() != 1) {
        w[a[l]].pop_front();
        if (w[a[l]].empty() != 1)
          ok[a[l]] -= (s[a[l]].front() - l) != w[a[l]].front();
      }
      all += (ok[a[l]] == 0) && !(s[a[l]].empty());
      l++;
    }
    while (r > q[i].r) {
      mp[a[r]]--;
      if (mp[a[r]] == 0) cnt--;
      all -= (ok[a[r]] == 0) && (!s[a[r]].empty());
      s[a[r]].pop_back();
      if (!s[a[r]].empty()) {
        w[a[r]].pop_back();
        if (!w[a[r]].empty())
          ok[a[r]] -= (r - s[a[r]].back()) != w[a[r]].back();
      }
      all += (ok[a[r]] == 0) && !(s[a[r]].empty());
      r--;
    }
    ans[q[i].i] = cnt + (all == 0);
  }
  for (int i = 1; i <= qu; i++) cout << ans[i] << "\n";
  return 0;
}
