#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const long double pi = acos(-1.0);
const int N = (int)1e6;
int sum[4 * N], m, pos[N], a[N], n, q, x, y, cmd;
int get(int t, int l, int r, int x, int y) {
  if ((r <= x) || (y <= l)) return 0;
  if ((x <= l) && (r <= y)) return sum[t];
  int m = (l + r) / 2;
  return get(t * 2 + 1, l, m, x, y) + get(t * 2 + 2, m, r, x, y);
}
void update(int t, int l, int r, int x, int value) {
  if ((x < l) || (x >= r)) return;
  if (l == r - 1) {
    assert(x == l);
    sum[t] = value;
    return;
  }
  int m = (l + r) / 2;
  update(t * 2 + 1, l, m, x, value);
  update(t * 2 + 2, m, r, x, value);
  sum[t] = sum[t * 2 + 1] + sum[t * 2 + 2];
}
void check(int x) {
  if (x > 0) update(0, 0, n, x - 1, (int)(pos[x - 1] > pos[x]));
  if (x + 1 < n) update(0, 0, n, x, (int)(pos[x] > pos[x + 1]));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    x--;
    pos[x] = i, a[i] = x;
  }
  for (int i = 0; i < n - 1; ++i)
    update(0, 0, n, i, (int)(pos[i] > pos[i + 1]));
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%d", &cmd, &x, &y);
    --x, --y;
    if (cmd == 1)
      printf("%d\n", 1 + get(0, 0, n, x, y));
    else {
      swap(a[x], a[y]);
      pos[a[x]] = x;
      pos[a[y]] = y;
      check(a[x]);
      check(a[y]);
    }
  }
  return 0;
}
