#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 1e9;
const int mod = 1e9 + 7;
int p[maxn], ind[maxn];
bool mark[maxn];
int fen[maxn];
int n;
void add(int x, int val) {
  for (; x <= n; x += x & -x) {
    fen[x] += val;
  }
}
int get(int x) {
  int sum = 0;
  for (; x > 0; x -= x & -x) {
    sum += fen[x];
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int m;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    ind[p[i]] = i;
  }
  cin >> m;
  ind[n + 1] = inf;
  for (int i = 1; i <= n; i++) {
    if (ind[i] > ind[i + 1]) {
      add(i, 1);
      mark[i] = true;
    }
  }
  while (m--) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r;
      cin >> l >> r;
      cout << get(r) - get(l - 1) + (ind[r] < ind[r + 1]) << endl;
    }
    if (t == 2) {
      int a, b;
      cin >> a >> b;
      swap(p[a], p[b]);
      ind[p[a]] = a;
      ind[p[b]] = b;
      add(p[b], (b > ind[p[b] + 1]) - mark[p[b]]);
      mark[p[b]] = (b > ind[p[b] + 1]);
      add(p[a], (a > ind[p[a] + 1]) - mark[p[a]]);
      mark[p[a]] = (a > ind[p[a] + 1]);
      if (p[b] > 1) add(p[b] - 1, (ind[p[b] - 1] > b) - mark[p[b] - 1]);
      mark[p[b] - 1] = (ind[p[b] - 1] > b);
      if (p[a] > 1) add(p[a] - 1, (ind[p[a] - 1] > a) - mark[p[a] - 1]);
      mark[p[a] - 1] = (ind[p[a] - 1] > a);
    }
  }
}
