#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
int T[MAXN];
int ids[MAXN];
int n;
int check(int a, int b) {
  vector<int> V(n);
  copy(T, T + n, V.begin());
  int m = 0;
  for (int i = 0; i < V.size(); i++) {
    if (V[i] == -1) continue;
    if (V[i] < a || V[i] > b) continue;
    int a = V[i];
    V[i] = -1;
    m++;
    for (int j = i + 1; j < V.size(); j++)
      if (V[j] == a + 1) {
        V[j] = -1;
        a++;
      }
  }
  return m;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &T[i]);
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int ot, a, b;
    scanf("%d %d %d", &ot, &a, &b);
    if (ot == 1) {
      printf("%d\n", check(a, b));
    } else {
      swap(T[a - 1], T[b - 1]);
    }
  }
  return 0;
}
