#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<pair<int, int> > sp;
int idx[1000006];
int n, x;
void gen() {
  sp.clear();
  for (int i = 1; i <= n;) {
    int r = i;
    for (int j = i + 1; j <= n; j++) {
      if (idx[j] > idx[j - 1]) {
        r = j;
      } else
        break;
    }
    sp.push_back(pair<int, int>(i, r));
    i = r + 1;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
    idx[x] = i;
  }
  int q;
  cin >> q;
  int c, l, r;
  gen();
  while (q--) {
    scanf("%d %d %d", &c, &l, &r);
    if (c == 1) {
      int cnt = 0;
      for (int i = 0; i < sp.size(); i++) {
        if (sp[i].first >= l && sp[i].second <= r) {
          cnt++;
        } else if (sp[i].first <= l && sp[i].second >= r) {
          cnt++;
        } else if (l >= sp[i].first && l <= sp[i].second) {
          cnt++;
        } else if (r >= sp[i].first && r <= sp[i].second) {
          cnt++;
        }
      }
      printf("%d\n", cnt);
    } else {
      swap(v[l - 1], v[r - 1]);
      swap(idx[v[l - 1]], idx[v[r - 1]]);
      gen();
    }
  }
  return 0;
}
