#include <bits/stdc++.h>
using namespace std;
int n, a[310000], pos[310000];
int c[310000];
void up(int x, int k) {
  for (int i = x; i <= n; i += (i & -i)) c[i] += k;
}
int cal(int x) {
  int res = 0;
  for (int i = x; i > 0; i -= (i & -i)) res += c[i];
  return res;
}
void sub(int x) {
  if (x > 1 && pos[x] < pos[x - 1]) up(x, -1);
  if (x < n && pos[x + 1] < pos[x]) up(x + 1, -1);
}
void add(int x) {
  if (x > 1 && pos[x] < pos[x - 1]) up(x, 1);
  if (x < n && pos[x + 1] < pos[x]) up(x + 1, 1);
}
int main() {
  int q, k, x, y;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  for (int i = 2; i <= n; ++i)
    if (pos[i] < pos[i - 1]) up(i, 1);
  cin >> q;
  while (q--) {
    scanf("%d %d %d", &k, &x, &y);
    if (k == 1)
      printf("%d\n", cal(y) - cal(x) + 1);
    else {
      if (abs(a[x] - a[y]) != 1) {
        swap(a[x], a[y]);
        sub(a[x]);
        sub(a[y]);
        pos[a[x]] = x;
        pos[a[y]] = y;
        add(a[x]);
        add(a[y]);
      } else {
        int xx = min(a[x], a[y]), yy = max(a[x], a[y]);
        if (xx > 1 && pos[xx] < pos[xx - 1]) up(xx, -1);
        if (pos[yy] < pos[xx]) up(yy, -1);
        if (yy < n && pos[yy + 1] < pos[yy]) up(yy + 1, -1);
        swap(a[x], a[y]);
        pos[a[x]] = x;
        pos[a[y]] = y;
        if (xx > 1 && pos[xx] < pos[xx - 1]) up(xx, 1);
        if (pos[yy] < pos[xx]) up(yy, 1);
        if (yy < n && pos[yy + 1] < pos[yy]) up(yy + 1, 1);
      }
    }
  }
  return 0;
}
