#include <bits/stdc++.h>
using namespace std;
int const N = 3e5 + 20;
int n, q, a[N], p[N];
int seg[N << 2];
void modify(int idx, int val, int v = 1, int s = 0, int e = n) {
  if (s + 1 == e) {
    seg[v] = val;
    return;
  }
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  if (idx < mid)
    modify(idx, val, lc, s, mid);
  else
    modify(idx, val, rc, mid, e);
  seg[v] = seg[lc] + seg[rc];
}
int get(int l, int r, int v = 1, int s = 0, int e = n) {
  if (s >= r || e <= l) return 0;
  if (s >= l && e <= r) return seg[v];
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  return get(l, r, lc, s, mid) + get(l, r, rc, mid, e);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], a[i]--, p[a[i]] = i;
  for (int i = 0; i < n - 1; i++)
    if (p[i] > p[i + 1]) modify(i, 1);
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int l, r;
      cin >> l >> r;
      l--, r--;
      cout << get(l, r) + 1 << '\n';
    } else {
      int x, y;
      cin >> x >> y;
      x = a[x - 1], y = a[y - 1];
      swap(a[p[x]], a[p[y]]), swap(p[x], p[y]);
      if (x > 0) {
        if (p[x] > p[x - 1])
          modify(x - 1, 0);
        else
          modify(x - 1, 1);
      }
      if (y > 0) {
        if (p[y] > p[y - 1])
          modify(y - 1, 0);
        else
          modify(y - 1, 1);
      }
      if (x < n - 1) {
        if (p[x] < p[x + 1])
          modify(x, 0);
        else
          modify(x, 1);
      }
      if (y < n - 1) {
        if (p[y] < p[y + 1])
          modify(y, 0);
        else
          modify(y, 1);
      }
    }
  }
}
