#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1000005;
int n, q;
int a[MAXN], pos[MAXN], pre[MAXN], nxt[MAXN];
int c[MAXN];
bool flag[MAXN];
void add(int i, int val) {
  if (i == 0) return;
  for (; i <= n + 2; i += i & -i) c[i] += val;
}
int sum(int i) {
  int res = 0;
  for (; i > 0; i -= i & -i) res += c[i];
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); i++) scanf("%d", a + i), pos[a[i]] = i;
  pos[0] = 0, pos[n + 1] = n + 1;
  for (int i = (1); i < (n + 1); i++) {
    if (pos[i + 1] < pos[i]) add(i + 1, 1), flag[i + 1] = 1;
  }
  scanf("%d", &q);
  int cnt = 0;
  for (int cas = (0); cas < (q); cas++) {
    int op, x, y;
    scanf("%d%d%d", &op, &x, &y);
    if (op == 1) {
      printf("%d\n", sum(y) - sum(x) + 1);
    } else if (op == 2) {
      swap(a[x], a[y]);
      x = a[x], y = a[y];
      flag[x] = flag[y] = flag[x + 1] = flag[y + 1] = 1;
      if (flag[x] && pos[x - 1] > pos[x]) add(x, -1), flag[x] = 0;
      if (flag[y] && pos[y - 1] > pos[y]) add(y, -1), flag[y] = 0;
      if (flag[x + 1] && pos[x] > pos[x + 1]) add(x + 1, -1), flag[x + 1] = 0;
      if (flag[y + 1] && pos[y] > pos[y + 1]) add(y + 1, -1), flag[y + 1] = 0;
      swap(pos[x], pos[y]);
      flag[x] = flag[y] = flag[x + 1] = flag[y + 1] = 1;
      if (flag[x] && pos[x - 1] > pos[x]) add(x, 1), flag[x] = 0;
      if (flag[y] && pos[y - 1] > pos[y]) add(y, 1), flag[y] = 0;
      if (flag[x + 1] && pos[x] > pos[x + 1]) add(x + 1, 1), flag[x + 1] = 0;
      if (flag[y + 1] && pos[y] > pos[y + 1]) add(y + 1, 1), flag[y + 1] = 0;
    }
  }
}
