#include <bits/stdc++.h>
using namespace std;
int n, i, q, p, x, y, to[310000], a[310000], b[310000], c[310000];
void read(int &x) {
  char k;
  for (k = getchar(); k <= 32; k = getchar())
    ;
  for (x = 0; '0' <= k; k = getchar()) x = x * 10 + k - '0';
}
void modify(int x, int y) {
  for (; x < n; x += x & -x) c[x] += y;
}
int get(int x) {
  int sum = 0;
  for (; x; x -= x & -x) sum += c[x];
  return sum;
}
int main() {
  read(n);
  for (i = 1; i <= n; i++) read(a[i]), to[a[i]] = i;
  for (i = 1; i < n; i++)
    if (to[i] > to[i + 1]) modify(i, 1), b[i] = 1;
  to[0] = 0;
  to[n + 1] = n + 1;
  read(q);
  while (q--) {
    read(p);
    read(x);
    read(y);
    if (p == 2) {
      if (b[a[x] - 1]) modify(a[x] - 1, -1), b[a[x] - 1] = 0;
      if (b[a[x]]) modify(a[x], -1), b[a[x]] = 0;
      if (b[a[y] - 1]) modify(a[y] - 1, -1), b[a[y] - 1] = 0;
      if (b[a[y]]) modify(a[y], -1), b[a[y]] = 0;
      swap(a[x], a[y]);
      swap(to[a[x]], to[a[y]]);
      if (!b[a[x] - 1] && to[a[x] - 1] > to[a[x]])
        modify(a[x] - 1, 1), b[a[x] - 1] = 1;
      if (!b[a[x]] && to[a[x]] > to[a[x] + 1]) modify(a[x], 1), b[a[x]] = 1;
      if (!b[a[y] - 1] && to[a[y] - 1] > to[a[y]])
        modify(a[y] - 1, 1), b[a[y] - 1] = 1;
      if (!b[a[y]] && to[a[y]] > to[a[y] + 1]) modify(a[y], 1), b[a[y]] = 1;
    } else
      printf("%d\n", get(y - 1) - get(x - 1) + 1);
  }
}
