#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 19;
const int inf = 1 << 30;
int n, a[N], b[N], c[N << 1];
void upd(int i) {
  int v = N + i - 1;
  if (i < n && b[i] > b[i + 1])
    c[v] = 1;
  else
    c[v] = 0;
  while (v > 1) {
    v /= 2;
    c[v] = c[v * 2] + c[v * 2 + 1];
  }
}
int sum(int l, int r) {
  l += N - 1;
  r += N - 1;
  int res = 0;
  while (l <= r) {
    if (l % 2 == 1) res += c[l++];
    if (r % 2 == 0) res += c[r--];
    l /= 2;
    r /= 2;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) b[a[i]] = i;
  for (int i = 1; i <= n; i++) upd(i);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int p, x, y;
    scanf("%d%d%d", &p, &x, &y);
    if (p == 1) {
      printf("%d\n", sum(x, y - 1) + 1);
    } else {
      swap(a[x], a[y]);
      b[a[x]] = x;
      b[a[y]] = y;
      upd(a[x] - 1);
      upd(a[x]);
      upd(a[y] - 1);
      upd(a[y]);
    }
  }
  return 0;
}
