#include <bits/stdc++.h>
using namespace std;
int n, A[300005], P[300005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    P[A[i]] = i;
  }
  int q;
  scanf("%d", &q);
  int p, x, y;
  int r;
  while (q--) {
    scanf("%d%d%d", &p, &x, &y);
    if (p == 2) {
      swap(P[A[x]], P[A[y]]);
      swap(A[x], A[y]);
    } else if (p == 1) {
      int last = 0;
      r = 1;
      for (int i = x; i <= y; i++) {
        if (P[i] < last) r++;
        last = P[i];
      }
      cout << r << endl;
    }
  }
  return 0;
}
