#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
int n, m, q;
int a[MAXN];
bool visit[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &q);
  while (q--) {
    int x, y, p;
    scanf("%d%d%d", &p, &x, &y);
    if (p == 1) {
      memset(visit, false, sizeof(visit));
      int now = 0;
      for (int i = 1; i <= n; i++) {
        if (a[i] >= x && a[i] <= y && (!visit[a[i]])) {
          now++;
          int las = a[i];
          for (int j = i; j <= n; j++) {
            if (a[j] == las + 1) {
              visit[a[j]] = true;
              las = a[j];
            }
          }
        }
      }
      printf("%d\n", now);
    } else {
      swap(a[x], a[y]);
    }
  }
  return 0;
}
