#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
inline void read(int *a, int n) {
  for (int i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
const int maxn = 3e5 + 10;
const int maxm = 1e6 + 10;
const int maxlg = 20;
const int base = 29;
const int base2 = 31;
const int mod2 = 1e9 + 9;
const int mod = 1e9 + 7;
const long long INF = 1e18 + 10;
const int SQ = 317 + 5;
int a[maxn], n;
int stree[4 * maxn];
int where[maxn];
inline void build(int p = 0, int l = 0, int r = n - 2) {
  if (l == r) {
    stree[p] = where[l + 1] < where[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(2 * p + 1, l, mid);
  build(2 * p + 2, mid + 1, r);
  stree[p] = stree[2 * p + 1] + stree[2 * p + 2];
}
inline int get(int ql, int qr, int p = 0, int l = 0, int r = n - 2) {
  if (l > qr || r < ql) return 0;
  if (l >= ql && r <= qr) return stree[p];
  int mid = (l + r) >> 1;
  return get(ql, qr, 2 * p + 1, l, mid) + get(ql, qr, 2 * p + 2, mid + 1, r);
}
inline void update(int qx, int p = 0, int l = 0, int r = n - 2) {
  if (l > qx || r < qx) return;
  if (l == r) {
    stree[p] = where[l + 1] < where[l];
    return;
  }
  int mid = (l + r) >> 1;
  update(qx, 2 * p + 1, l, mid), update(qx, 2 * p + 2, mid + 1, r);
  stree[p] = stree[2 * p + 1] + stree[2 * p + 2];
}
int32_t main() {
  n = in();
  memset(where, -1, sizeof where);
  read(a, n);
  for (int i = 0; i < n; i++) where[--a[i]] = i;
  build();
  int q = in();
  while (q--) {
    int tp = in(), a = in() - 1, b = in() - 1;
    if (tp == 1) {
      b--;
      cout << get(a, b) + 1 << "\n";
      continue;
    }
    swap(::a[a], ::a[b]);
    swap(where[::a[a]], where[::a[b]]);
    int q[4] = {::a[a], ::a[b], ::a[a] - 1, ::a[b] - 1};
    for (int pt = 0; pt < 4; pt++) {
      if (q[pt] >= 0 && q[pt] < n - 1) {
        update(q[pt]);
      }
    }
  }
}
