#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, ar[200], pos[200];
  while (cin >> N) {
    for (int i = 0, _n = N; i < _n; i++) {
      scanf("%d", &ar[i]);
      pos[ar[i]] = i;
    }
    int Q;
    scanf("%d", &Q);
    while (Q--) {
      int T, x, y;
      cin >> T >> x >> y;
      if (T == 1) {
        vector<int> V;
        int color[100], t = 0;
        memset(color, 0, sizeof(color));
        for (int i = x, _n = y + 1; i < _n; i++) {
          int p = pos[i];
          int last = i - 1;
          if (!color[p]) {
            for (int j = p, _n = N; j < _n; j++)
              if (ar[j] == last + 1) color[j] = 1, last++;
            t++;
          }
        }
        cout << t << endl;
      } else {
        x--, y--;
        pos[ar[x]] = y;
        pos[ar[y]] = x;
        swap(ar[x], ar[y]);
      }
    }
  }
  return 0;
}
