#include <bits/stdc++.h>
using namespace std;
int a[105];
int pos[105];
int main() {
  ios_base::sync_with_stdio(false);
  int n = 0;
  cin >> n;
  pos[0] = 1000000000;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  int q = 0;
  cin >> q;
  while (q--) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      int count = 1;
      for (int i = x + 1; i <= y; ++i) {
        if (pos[i - 1] > pos[i]) ++count;
      }
      cout << count << "\n";
    } else {
      pos[a[x]] = y;
      pos[a[y]] = x;
      swap(a[x], a[y]);
    }
  }
  return 0;
}
