#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int tree[600010 << 2], add[600010 << 2];
inline void deal(int x, int y) {
  tree[x] += y;
  add[x] += y;
}
inline void pushdown(int rt) {
  if (add[rt]) deal(rt << 1, add[rt]), deal(rt << 1 | 1, add[rt]), add[rt] = 0;
}
inline void updata(int L, int R, int y, int l, int r, int rt) {
  if (L > R) return;
  if (L <= l && r <= R) {
    deal(rt, y);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(rt);
  if (mid < R) updata(L, R, y, mid + 1, r, rt << 1 | 1);
  if (mid >= L) updata(L, R, y, l, mid, rt << 1);
}
inline int query(int x, int l, int r, int rt) {
  if (x == 0) return 1;
  if (l == r) return tree[rt];
  int mid = (l + r) >> 1;
  pushdown(rt);
  if (mid >= x) return query(x, l, mid, rt << 1);
  if (mid < x) return query(x, mid + 1, r, rt << 1 | 1);
}
int n, A[600010], B[600010], q;
inline void mmd(int x, int y) {
  if (A[x - 1] > A[x]) updata(x, n, -1, 1, n, 1);
  if (A[x] > A[x + 1]) updata(x + 1, n, -1, 1, n, 1);
  if (A[x - 1] > y) updata(x, n, 1, 1, n, 1);
  if (y > A[x + 1]) updata(x + 1, n, 1, 1, n, 1);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) B[i] = read(), A[B[i]] = i;
  q = read();
  A[n + 1] = n + 1;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cnt++;
    int j = i;
    while (A[j + 1] > A[j] && j + 1 <= n) j++;
    for (int t = i; t <= j; t++) updata(t, t, cnt, 1, n, 1);
    i = j;
  }
  for (int i = 1; i <= q; i++) {
    int op = read(), x = read(), y = read();
    if (op == 2) {
      int xx = B[x], yy = B[y], t2 = A[yy], t1 = A[xx];
      mmd(xx, t2);
      A[xx] = A[yy];
      mmd(yy, t1);
      A[yy] = A[xx];
      swap(B[x], B[y]);
      A[B[x]] = x;
      A[B[y]] = y;
    } else {
      int d1 = query(x - 1, 1, n, 1), d2 = query(y, 1, n, 1);
      if (A[x - 1] < A[x])
        printf("%d\n", d2 - d1 + 1);
      else
        printf("%d\n", d2 - d1);
    }
  }
  return 0;
}
