#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
int n, m;
int a[MAXN], t[MAXN], pos[MAXN];
inline int lowbit(int i) { return i & (-i); }
void add(int x, int k) {
  for (int i = x; i <= n; i += lowbit(i)) t[i] += k;
}
int get(int x) {
  int res = 0;
  for (int i = x; i; i -= lowbit(i)) res += t[i];
  return res;
}
void query(int x, int y) {
  int ans = get(y) - get(x) + 1;
  printf("%d\n", ans);
}
void change(int x, int y) {
  if (x > pos[a[x] - 1] && y <= pos[a[x] - 1]) add(a[x], 1);
  if (x < pos[a[x] - 1] && y >= pos[a[x] - 1]) add(a[x], -1);
  if (pos[a[x] + 1] > x && pos[a[x] + 1] <= y) add(a[x] + 1, 1);
  if (pos[a[x] + 1] < x && pos[a[x] + 1] >= y) add(a[x] + 1, -1);
  if (a[x] + 1 != a[y]) {
    if (y > pos[a[y] - 1] && x <= pos[a[y] - 1]) add(a[y], 1);
    if (y < pos[a[y] - 1] && x >= pos[a[y] - 1]) add(a[y], -1);
  }
  if (a[y] + 1 != a[x]) {
    if (pos[a[y] + 1] > y && pos[a[y] + 1] <= x) add(a[y] + 1, 1);
    if (pos[a[y] + 1] < y && pos[a[y] + 1] >= x) add(a[y] + 1, -1);
  }
  swap(pos[a[x]], pos[a[y]]);
  swap(a[x], a[y]);
}
int main() {
  memset(pos, 0xff, sizeof(pos));
  scanf("%d", &n);
  pos[0] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (pos[a[i] - 1] == -1) add(a[i], 1);
    pos[a[i]] = i;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int p, x, y;
    scanf("%d %d %d", &p, &x, &y);
    if (p == 1)
      query(x, y);
    else
      change(x, y);
  }
  return 0;
}
