#include <bits/stdc++.h>
using namespace std;
int s[301000 << 2] = {0};
int id[301000];
int a[301000];
int n;
void push_up(int rt) { s[rt] = s[rt << 1] + s[rt << 1 | 1]; }
void update(int id, int c, int l, int r, int rt) {
  if (l == r) {
    s[rt] = c;
    return;
  }
  int mid = (l + r) >> 1;
  if (id <= mid)
    update(id, c, l, mid, rt << 1);
  else
    update(id, c, mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
int query(int L, int R, int l, int r, int rt) {
  if (L <= l && R >= r) return s[rt];
  int mid = (l + r) >> 1;
  if (R <= mid)
    return query(L, R, l, mid, rt << 1);
  else if (L > mid)
    return query(L, R, mid + 1, r, rt << 1 | 1);
  else
    return query(L, mid, l, mid, rt << 1) +
           query(mid + 1, R, mid + 1, r, rt << 1 | 1);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    id[a[i]] = i;
  }
  update(1, 1, 1, n, 1);
  for (int i = 1; i < n; i++) {
    if (id[i + 1] < id[i]) {
      update(i + 1, 1, 1, n, 1);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int op, x, y;
    cin >> op >> x >> y;
    if (op == 2) {
      swap(id[a[x]], id[a[y]]);
      swap(a[x], a[y]);
      int i = a[x], j = a[y];
      if (a[x] > 1) {
        int t = id[a[x] - 1] > id[a[x]];
        update(a[x], t, 1, n, 1);
      }
      if (a[x] < n) {
        int t = id[a[x]] > id[a[x] + 1];
        update(a[x] + 1, t, 1, n, 1);
      }
      if (a[y] > 1) {
        int t = id[a[y] - 1] > id[a[y]];
        update(a[y], t, 1, n, 1);
      }
      if (a[y] < n) {
        int t = id[a[y]] > id[a[y] + 1];
        update(a[y] + 1, t, 1, n, 1);
      }
    } else {
      int t = query(x, x, 1, n, 1);
      int ans = query(x, y, 1, n, 1);
      if (!t) ans += 1;
      printf("%d\n", ans);
    }
  }
  return 0;
}
