#include <bits/stdc++.h>
const int MaxN = 3e5;
int n, m, a[MaxN], p[MaxN];
int leaf, tr[MaxN * 2];
void build(int n) {
  leaf = n;
  for (int i = 0; i < n; ++i) tr[i + leaf] = a[i] > a[i + 1];
  for (int i = leaf - 1; i; --i) tr[i] = tr[i << 1] + tr[i << 1 | 1];
}
void upd(int x, int val) {
  tr[x += leaf] += val;
  while (x >>= 1) tr[x] += val;
}
int find(int l, int r) {
  int ans = 0;
  for (l += leaf, r += leaf; l <= r; l >>= 1, r >>= 1) {
    if (l & 1) ans += tr[l++];
    if (~r & 1) ans += tr[r--];
  }
  return ans;
}
void adjust(int x) {
  int _x = x + leaf;
  if (x) {
    if (tr[_x - 1] && a[x - 1] < a[x]) upd(x - 1, -1);
    if (!tr[_x - 1] && a[x - 1] > a[x]) upd(x - 1, 1);
  }
  if (x < n - 1) {
    if (tr[_x] && a[x] < a[x + 1]) upd(x, -1);
    if (!tr[_x] && a[x] > a[x + 1]) upd(x, 1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", p + i);
    a[--p[i]] = i;
  }
  build(n);
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int type;
    scanf("%d", &type);
    if (type & 1) {
      int l, r;
      scanf("%d %d", &l, &r);
      printf("%d\n", 1 + find(l - 1, r - 2));
    } else {
      int x, y;
      scanf("%d %d", &x, &y);
      --x;
      --y;
      std::swap(a[p[x]], a[p[y]]);
      std::swap(p[x], p[y]);
      adjust(p[x]);
      adjust(p[y]);
    }
  }
  return 0;
}
