#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long INF64 = (long long)1e18;
const long double eps = 1e-9;
const long double pi = 3.14159265358979323846;
int nu[200];
int loc[200];
int main() {
  int i, j;
  int cnt;
  int n, qn;
  int q, a, b;
  while (cin >> n) {
    for (i = 1; i <= n; i++) {
      cin >> nu[i];
      loc[nu[i]] = i;
    }
    cin >> qn;
    while (qn--) {
      cin >> q >> a >> b;
      if (q == 2) {
        swap(loc[nu[a]], loc[nu[b]]);
        swap(nu[a], nu[b]);
      } else {
        cnt = 0;
        for (i = a; i <= b; i++) {
          for (j = i + 1; j <= b && loc[j - 1] <= loc[j]; j++)
            ;
          cnt++;
          i = j - 1;
        }
        printf("%d\n", cnt);
      }
    }
  }
  return 0;
}
