#include <bits/stdc++.h>
using namespace std;
int sss[444444], p[444444], a[444444], n, b[444444], c[444444];
inline void upd(int x, int v) {
  for (int j = x; j < n + 11; j |= (j + 1)) sss[j] += v;
}
inline int fs(int x) {
  if (x < 0) return 0;
  int res = 0;
  for (int j = x; j >= 0; j = (j & (j + 1)) - 1) res += sss[j];
  return res;
}
inline void changel(int x, int y, int p) {
  if (!p) return;
  if (p < x && p < y) return;
  if (p > x && p > y) return;
  if (p < x && p > y)
    upd(a[p], 1);
  else if (p > x && p < y)
    upd(a[p], -1);
}
inline void changer(int x, int y, int p) {
  if (!p) return;
  if (p > x && p > y) return;
  if (p < x && p < y) return;
  if (p > x && p < y)
    upd(a[x], 1);
  else if (p < x && p > y)
    upd(a[x], -1);
}
inline void swp(int x, int y) {
  if (x > y) swp(x, y);
  if (((a[x] - a[y]) > 0 ? (a[x] - a[y]) : -(a[x] - a[y])) == 1) {
    if (a[x] < a[y]) {
      changel(x, y, p[a[x] - 1]);
      upd(a[x], 1);
      changer(y, x, p[a[y] + 1]);
    } else {
      changel(y, x, p[a[y] - 1]);
      upd(a[y], -1);
      changer(x, y, p[a[x] + 1]);
    }
  } else {
    changel(x, y, p[a[x] - 1]);
    changer(x, y, p[a[x] + 1]);
    changel(y, x, p[a[y] - 1]);
    changer(y, x, p[a[y] + 1]);
  }
  swap(a[x], a[y]);
  p[a[x]] = x;
  p[a[y]] = y;
}
int main(int argc, char* argv[]) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), p[a[i]] = i;
  for (int i = 1; i <= n; i++)
    if (a[i] != n && p[a[i] + 1] < i) upd(a[i], 1);
  int ttt;
  scanf("%d", &ttt);
  while (ttt--) {
    int q;
    scanf("%d", &q);
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    if (q == 1) {
      int ans = 0;
      if (x == y)
        ans = 0;
      else
        ans = fs(y - 1) - fs(x - 1);
      printf("%d\n", ans + 1);
    } else {
      if (x == y) continue;
      swp(x, y);
    }
  }
  return 0;
}
