#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 20;
struct node {
  int sum, siz;
};
node f[N * 4];
int a[N], rd[N];
void pushup(int u) {
  int ls = u * 2, rs = u * 2 + 1;
  f[u].sum = f[ls].sum + f[rs].sum;
}
void build(int u, int l, int r) {
  f[u].siz = r - l + 1;
  if (l == r) {
    f[u].sum = (a[l] < a[l + 1]);
    return;
  }
  int mid = l + r >> 1;
  build(u * 2, l, mid);
  build(u * 2 + 1, mid + 1, r);
  pushup(u);
}
void update(int u, int l, int r, int x) {
  if (x < l || x > r) return;
  if (l == r) {
    f[u].sum = (a[l] < a[l + 1]);
    return;
  }
  int mid = l + r >> 1;
  update(u * 2, l, mid, x);
  update(u * 2 + 1, mid + 1, r, x);
  pushup(u);
}
int query(int u, int l, int r, int x, int y) {
  if (l > y || r < x) return 0;
  if (x <= l && r <= y) {
    return f[u].sum;
  }
  int mid = l + r >> 1;
  return query(u * 2, l, mid, x, y) + query(u * 2 + 1, mid + 1, r, x, y);
}
int main() {
  int n, q, x, y, opt;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &rd[i]), a[rd[i]] = i;
  scanf("%d", &q);
  build(1, 1, n);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d", &opt, &x, &y);
    if (opt == 1) {
      printf("%d\n", y - x - query(1, 1, n, x, y - 1) + 1);
    } else {
      swap(a[rd[x]], a[rd[y]]);
      swap(rd[x], rd[y]);
      update(1, 1, n, rd[x] - 1);
      update(1, 1, n, rd[y] - 1);
      update(1, 1, n, rd[x]);
      update(1, 1, n, rd[y]);
    }
  }
  return 0;
}
