#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int n, q, sw;
int d[110], e[110];
void nop() { int a = 5; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    e[d[i]] = i;
  }
  cin >> q;
  for (int z = 0; z < q; z++) {
    int p, a, b;
    scanf("%d%d%d", &p, &a, &b);
    if (p == 1) {
      int last = 0;
      int k = 0;
      for (int i = a; i <= b; i++) {
        if (last > e[i]) k++;
        last = e[i];
      }
      cout << k + 1 << endl;
      continue;
    };
    if (p == 2) {
      int t = e[d[a]];
      e[d[a]] = e[d[b]];
      e[d[b]] = t;
      t = d[a];
      d[a] = d[b];
      d[b] = t;
    }
  }
  return 0;
};
