#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const int MAXN = 3e5 + 54;
int sign(double x) { return x < -EPS ? -1 : x > EPS; }
int dbcmp(double l, double r) { return sign(l - r); }
int a[MAXN], pos[MAXN], tree[MAXN << 2];
void build(int rt, int l, int r) {
  if (l == r) {
    tree[rt] = pos[l] < pos[l - 1];
    return;
  }
  int mid = l + r >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
}
int query(int rt, int L, int R, int l, int r) {
  if (L > r || l > R) return 0;
  if (l <= L && R <= r) return tree[rt];
  int mid = L + R >> 1, ans = 0;
  if (l <= mid) ans += query(rt << 1, L, mid, l, r);
  if (r > mid) ans += query(rt << 1 | 1, mid + 1, R, l, r);
  return ans;
}
void update(int rt, int l, int r, int x, int v) {
  if (l == r) {
    tree[rt] = v;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    update(rt << 1, l, mid, x, v);
  else
    update(rt << 1 | 1, mid + 1, r, x, v);
  tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
}
int main() {
  int n, q;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  scanf("%d", &q);
  build(1, 1, n + 1);
  for (int i = 1; i <= q; i++) {
    int op, x, y;
    scanf("%d%d%d", &op, &x, &y);
    if (op == 1)
      printf("%d\n", x == y ? 1 : (1 + query(1, 1, n + 1, x + 1, y)));
    else {
      int pos1 = a[x], pos2 = a[y];
      swap(a[x], a[y]);
      swap(pos[pos1], pos[pos2]);
      update(1, 1, n + 1, pos1, pos[pos1 - 1] > pos[pos1]);
      update(1, 1, n + 1, pos1 + 1, pos[pos1] > pos[pos1 + 1]);
      update(1, 1, n + 1, pos2 + 1, pos[pos2] > pos[pos2 + 1]);
      update(1, 1, n + 1, pos2, pos[pos2 - 1] > pos[pos2]);
    }
  }
}
