#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 100;
int n, q, a[N], sh[N], t[N], b[N];
inline int lowbit(int x) { return x & (-x); }
inline void change(int x, int v) {
  while (x <= n) sh[x] += v, x += lowbit(x);
}
inline int query(int x) {
  int ans = 0;
  while (x) ans += sh[x], x -= lowbit(x);
  return ans;
}
inline int read() {
  int f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
signed main() {
  n = read();
  for (int i = 1; i <= n; i++) b[i] = read(), a[b[i]] = i;
  for (int i = 1; i <= n; i++)
    if (a[i] < a[i - 1]) change(i, 1);
  a[n + 1] = n + 1;
  q = read();
  while (q--) {
    int op = read(), x = read(), y = read();
    if (op == 1)
      printf("%d\n", query(y) - query(x) + 1);
    else {
      int tx = x, ty = y;
      x = b[x];
      y = b[y];
      swap(b[tx], b[ty]);
      t[x] = t[x + 1] = t[y] = t[y + 1] = 0;
      if (a[x] < a[x - 1]) change(x, -1), t[x] = 1;
      if (a[x + 1] < a[x]) change(x + 1, -1), t[x + 1] = 1;
      if (a[y] < a[y - 1] && !t[y]) change(y, -1), t[y] = 1;
      if (a[y + 1] < a[y] && !t[y + 1]) change(y + 1, -1), t[y + 1] = 1;
      swap(a[x], a[y]);
      t[x] = t[x + 1] = t[y] = t[y + 1] = 0;
      if (a[x] < a[x - 1]) change(x, 1), t[x] = 1;
      if (a[x + 1] < a[x]) change(x + 1, 1), t[x + 1] = 1;
      if (a[y] < a[y - 1] && !t[y]) change(y, 1), t[y] = 1;
      if (a[y + 1] < a[y] && !t[y + 1]) change(y + 1, 1), t[y + 1] = 1;
    }
  }
}
