#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
bool vis[N];
int pos[N];
int a[N];
int s[N << 2];
void update(int p, int x, int l, int r, int rt) {
  if (l == r) {
    s[rt] = x;
    return;
  }
  int m = (l + r) >> 1;
  if (p <= m)
    update(p, x, l, m, (rt << 1));
  else
    update(p, x, m + 1, r, (rt << 1 | 1));
  s[rt] = s[(rt << 1)] + s[(rt << 1 | 1)];
}
int query(int ql, int qr, int l, int r, int rt) {
  if (ql <= l && r <= qr) {
    return s[rt];
  }
  int m = (l + r) >> 1;
  int res = 0;
  if (ql <= m) res += query(ql, qr, l, m, (rt << 1));
  if (qr > m) res += query(ql, qr, m + 1, r, (rt << 1 | 1));
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  memset(s, 0, sizeof(s));
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
    if (!vis[a[i] - 1]) update(a[i], 1, 1, n, 1);
    vis[a[i]] = true;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int p, x, y;
    scanf("%d%d%d", &p, &x, &y);
    if (p == 1) {
      int ans = query(x + 1, y, 1, n, 1) + 1;
      printf("%d\n", ans);
    } else {
      swap(a[x], a[y]);
      pos[a[x]] = x;
      pos[a[y]] = y;
      if (a[x] < n) {
        if (pos[a[x] + 1] > x)
          update(a[x] + 1, 0, 1, n, 1);
        else
          update(a[x] + 1, 1, 1, n, 1);
      }
      if (a[y] < n) {
        if (pos[a[y] + 1] > y)
          update(a[y] + 1, 0, 1, n, 1);
        else
          update(a[y] + 1, 1, 1, n, 1);
      }
      if (a[x] > 1) {
        if (pos[a[x] - 1] < x)
          update(a[x], 0, 1, n, 1);
        else
          update(a[x], 1, 1, n, 1);
      }
      if (a[y] > 1) {
        if (pos[a[y] - 1] < y)
          update(a[y], 0, 1, n, 1);
        else
          update(a[y], 1, 1, n, 1);
      }
    }
  }
  return 0;
}
