#include <bits/stdc++.h>
using namespace std;
int arr[110];
int pos[110];
int query(int x, int y) {
  int cnt = 1;
  for (int i = x + 1; i <= y; i++) {
    if (pos[i] < pos[i - 1]) cnt++;
  }
  return cnt;
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> arr[i];
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int a, x, y;
    cin >> a >> x >> y;
    if (a == 2)
      swap(arr[x - 1], arr[y - 1]);
    else {
      for (int j = 0; j < N; j++) pos[arr[j]] = j;
      cout << query(x, y) << endl;
    }
  }
}
