#include <bits/stdc++.h>
using namespace std;
long n, ar[500000], ps[500000], q, tp, a, b, bd[500000], sb[500000];
long res, fb;
long gs(long v) {
  fb = v / 330;
  res = 0;
  for (int i = 0; i < fb; i++) res += sb[i];
  for (int i = fb * 330; i <= v; i++) res += bd[i];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    ps[ar[i]] = i;
  }
  for (int i = 2; i <= n; i++)
    if (ps[i] < ps[i - 1]) {
      bd[i] = 1;
      sb[i / 330]++;
    }
  cin >> q;
  for (; q; --q) {
    cin >> tp;
    if (tp == 1) {
      cin >> a >> b;
      cout << gs(b) - gs(a) + 1 << endl;
    } else {
      cin >> a >> b;
      swap(ar[a], ar[b]);
      ps[ar[a]] = a;
      ps[ar[b]] = b;
      a = ar[a];
      b = ar[b];
      sb[a / 330] -= bd[a];
      sb[b / 330] -= bd[b];
      sb[(a + 1) / 330] -= bd[a];
      sb[(b + 1) / 330] -= bd[b];
      bd[a] = bd[b] = bd[a + 1] = bd[b + 1] = 0;
      if (a > 1 && ps[a] < ps[a - 1]) {
        bd[a] = 1;
        sb[a / 330]++;
      }
      if (a < n && ps[a] > ps[a + 1]) {
        bd[a + 1] = 1;
        sb[(a + 1) / 330]++;
      }
      if (b > 1 && ps[b] < ps[b - 1]) {
        sb[b / 330] += 1 - bd[b];
        bd[b] = 1;
      }
      if (b < n && ps[b] > ps[b + 1]) {
        sb[(b + 1) / 330] += 1 - bd[b + 1];
        bd[b + 1] = 1;
      }
    }
  }
  cin.get();
  cin.get();
  return 0;
}
