#include <bits/stdc++.h>
using namespace std;
int a[500000], b[500000], dif[500000];
int n;
vector<int> T;
void update(int r, int x) {
  for (; r <= n; r |= (r + 1)) T[r] += x;
}
int get0(int l) {
  int res = 0;
  for (; l > 0; l = (l & (l + 1)) - 1) res += T[l];
  return res;
}
int get(int l, int r) { return get0(r) - get0(l - 1); }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) a[b[i]] = i;
  for (int i = 1; i <= n; i++) dif[i] = (a[i] - a[i - 1] < 0);
  int q;
  cin >> q;
  T.assign(n + 1, 0);
  for (int i = 1; i <= n; i++) update(i, dif[i]);
  for (int i = 2; i <= n; i++) dif[i] = a[i] - a[i - 1];
  for (; q; --q) {
    int p, l, r;
    cin >> p >> l >> r;
    if (p == 1)
      cout << get(l + 1, r) + 1 << endl;
    else {
      int x = l, y = r;
      swap(b[x], b[y]);
      l = b[x], r = b[y];
      if (dif[l] < 0 && dif[l] - a[l] + a[r] >= 0)
        update(l, -1);
      else if (dif[l] >= 0 && dif[l] - a[l] + a[r] < 0)
        update(l, 1);
      if (dif[l + 1] < 0 && dif[l + 1] + a[l] - a[r] >= 0)
        update(l + 1, -1);
      else if (dif[l + 1] >= 0 && dif[l + 1] + a[l] - a[r] < 0)
        update(l + 1, 1);
      dif[l] = dif[l] - a[l] + a[r];
      dif[l + 1] = dif[l + 1] + a[l] - a[r];
      if (dif[r] < 0 && dif[r] - a[r] + a[l] >= 0)
        update(r, -1);
      else if (dif[r] >= 0 && dif[r] - a[r] + a[l] < 0)
        update(r, 1);
      if (r < n)
        if (dif[r + 1] < 0 && dif[r + 1] + a[r] - a[l] >= 0)
          update(r + 1, -1);
        else if (dif[r + 1] >= 0 && dif[r + 1] + a[r] - a[l] < 0)
          update(r + 1, 1);
      dif[r] = dif[r] - a[r] + a[l];
      if (r < n) dif[r + 1] = dif[r + 1] + a[r] - a[l];
      swap(a[l], a[r]);
    }
  }
  return 0;
}
