#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
const int maxn = 3 * (int)1e5 + 5;
int n;
int a[maxn];
int p[maxn];
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    p[a[i]] = i;
  }
  int q;
  cin >> q;
  while (q--) {
    int tst, x, y;
    cin >> tst >> x >> y;
    if (tst == 2) {
      swap(a[x], a[y]);
      p[a[x]] = x;
      p[a[y]] = y;
    } else {
      int ans = 1;
      int last = -1;
      for (int i = x; i <= y; ++i) {
        if (p[i] < last) ++ans;
        last = p[i];
      }
      cout << ans << endl;
    }
  }
  return 0;
}
