#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N], pre[N], pos[N], fa[N];
int n, m;
int find_fa(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find_fa(fa[x]);
}
void unin(int x, int y) {
  int a = find_fa(x);
  int b = find_fa(y);
  fa[a] = b;
}
void fun() {
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 2; i <= n; i++) {
    if (pos[i - 1] < pos[i]) unin(i - 1, i);
  }
}
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      pos[a[i]] = i;
    }
    fun();
    scanf("%d", &m);
    while (m--) {
      int q, x, y;
      scanf("%d%d%d", &q, &x, &y);
      if (q == 1) {
        int ans = 0;
        bool vis[N] = {0};
        for (int i = x; i <= y; i++) {
          if (vis[find_fa(i)] == 0) {
            ans++;
            vis[find_fa(i)] = 1;
          }
        }
        printf("%d\n", ans);
      } else {
        swap(a[x], a[y]);
        swap(pos[a[x]], pos[a[y]]);
        fun();
      }
    }
  }
  return 0;
}
