#include <bits/stdc++.h>
using namespace std;
int N[300005], P[300005];
int T[300005];
void Add(int i, int m) {
  for (; i < 300005; i += i & (-i)) T[i] += m;
}
int Sum(int i) {
  int t, sum = 0;
  for (; i; i -= i & (-i)) sum += T[i];
  return sum;
}
int Count_sum(int i, int j) { return Sum(j) - Sum(i - 1); }
int Work(int x, int y) {
  int res = 0, i, bef = 300005;
  res = Count_sum(x + 1, y);
  return res;
}
void Done(int x, int y) {
  if (P[x - 1] < P[x] && P[x - 1] >= P[y]) Add(x, 1);
  if (P[x - 1] > P[x] && P[x - 1] <= P[y]) Add(x, -1);
  if (P[x] > P[x + 1] && P[y] <= P[x + 1] && y != x + 1) Add(x + 1, -1);
  if (P[x] < P[x + 1] && P[y] >= P[x + 1] && y != x + 1) Add(x + 1, 1);
}
void Do(int x, int y) {
  Done(x, y);
  Done(y, x);
}
int main() {
  int i, j, n, m;
  for (i = scanf("%d", &n); i <= n; i++) scanf("%d", &N[i]), P[N[i]] = i;
  for (i = 1; i <= n; i++)
    if (P[i] < P[i - 1]) Add(i, 1);
  int p, x, y;
  for (i = scanf("%d", &n); i <= n; i++) {
    scanf("%d%d%d", &p, &x, &y);
    if (p == 1) {
      printf("%d\n", Work(x, y) + 1);
    } else
      Do(N[x], N[y]), swap(N[x], N[y]), P[N[x]] = x, P[N[y]] = y;
  }
  return 0;
}
