#include <bits/stdc++.h>
using namespace std;
int pos[300005];
int id[300005];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    --x;
    pos[x] = i;
    id[i] = x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int t, x, y;
    cin >> t >> x >> y;
    --x;
    --y;
    if (t == 1) {
      int ret = 1;
      for (int i = x; i < y; ++i) {
        if (pos[i] > pos[i + 1]) {
          ++ret;
        }
      }
      printf("%d\n", ret);
    } else {
      int ps1 = id[x], ps2 = id[y];
      swap(id[x], id[y]);
      swap(pos[ps1], pos[ps2]);
    }
  }
  return 0;
}
