#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int tree[maxn];
void update(int pos, int val) {
  while (pos < maxn) tree[pos] += val, pos += pos & -pos;
}
int query(int pos) {
  int ans = 0;
  while (pos) ans += tree[pos], pos -= pos & -pos;
  return ans;
}
int pos[maxn];
int a[maxn];
int f[maxn];
int n;
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) pos[a[i]] = i;
    memset(f, 0, sizeof(f));
    for (int i = 1; i < n; i++) {
      if (pos[i + 1] < pos[i]) {
        f[i] = 1;
        update(i, 1);
      }
    }
    int q;
    scanf("%d", &q);
    while (q--) {
      int type, x, y;
      scanf("%d %d %d", &type, &x, &y);
      if (type == 1) {
        int ans = query(y - 1) - query(x - 1) + 1;
        printf("%d\n", ans);
      } else {
        if (x == y) continue;
        int xx = f[a[x]];
        int yy = f[a[y]];
        pos[a[x]] = y;
        pos[a[y]] = x;
        int newx = 0, newy = 0;
        if (a[x] != n) {
          if (pos[a[x] + 1] < pos[a[x]]) newx = 1;
        }
        if (a[y] != n) {
          if (pos[a[y] + 1] < pos[a[y]]) newy = 1;
        }
        update(a[x], newx - xx);
        update(a[y], newy - yy);
        f[a[x]] = newx;
        f[a[y]] = newy;
        swap(a[x], a[y]);
        if (a[x] - 1 > 0 && a[x] - 1 != a[y]) {
          int nn = 0;
          if (pos[a[x]] < pos[a[x] - 1]) nn = 1;
          update(a[x] - 1, nn - f[a[x] - 1]);
          f[a[x] - 1] = nn;
        }
        if (a[y] - 1 > 0 && a[y] - 1 != a[x]) {
          int nn = 0;
          if (pos[a[y]] < pos[a[y] - 1]) nn = 1;
          update(a[y] - 1, nn - f[a[y] - 1]);
          f[a[y] - 1] = nn;
        }
      }
    }
  }
}
