#include <bits/stdc++.h>
using namespace std;
int arr[110];
map<int, int> m;
void swap(int x, int y) {
  int tmp = arr[x];
  arr[x] = arr[y];
  arr[y] = tmp;
  m[arr[x]] = x;
  m[arr[y]] = y;
}
void eval(int n, int x, int y) {
  int ans = 0;
  int i = x;
  while (true) {
    if (i > y) break;
    while (true) {
      int pos1 = m[i];
      int pos2 = m[i + 1];
      if (pos2 > pos1)
        i++;
      else
        break;
      if (i > y) break;
    }
    i++;
    ans++;
  }
  cout << ans << endl;
}
int main() {
  int n, q;
  int qType;
  int x, y;
  cin >> n;
  arr[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    m[arr[i]] = i;
  }
  cin >> q;
  while (q--) {
    cin >> qType >> x >> y;
    if (qType == 2)
      swap(x, y);
    else
      eval(n, x, y);
  }
  return 0;
}
