#include <bits/stdc++.h>
using namespace std;
int n, q, p, t, x, y;
int pos[102];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p;
    pos[p] = i + 1;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t;
    if (t == 2) {
      cin >> x >> y;
      int a, b;
      for (int j = 1; j < n + 1; j++) {
        if (pos[j] == x) a = j;
        if (pos[j] == y) b = j;
      }
      pos[a] ^= pos[b] ^= pos[a] ^= pos[b];
    } else {
      cin >> x >> y;
      int s = 1, p = pos[x];
      for (int j = x + 1; j <= y; j++) {
        if (pos[j] < p) s++;
        p = pos[j];
      }
      cout << s << "\n";
    }
  }
  return 0;
}
