#include <bits/stdc++.h>
using namespace std;
int a[310000];
int main() {
  int N, M, i, t, x, y;
  cin >> N;
  for (i = 1; i <= N; i++) {
    cin >> x;
    a[x] = i;
  }
  cin >> M;
  while (M--) {
    cin >> t >> x >> y;
    if (t == 1) {
      int res = 1;
      for (i = x + 1; i <= y; i++) {
        if (a[i] < a[i - 1]) ++res;
      }
      cout << res << endl;
    } else {
      int p, q;
      for (i = 1; i <= N; i++) {
        if (a[i] == x) p = i;
        if (a[i] == y) q = i;
      }
      swap(a[p], a[q]);
    }
  }
}
