#include <bits/stdc++.h>
using namespace std;
int n, a[301000], b[301000], where[301000];
struct Segment_Tree {
  int left, right;
  int dp, lazy;
} tree[301000 << 2];
void plant_tree(int id, int l, int r) {
  tree[id].left = l, tree[id].right = r;
  tree[id].lazy = 0;
  if (l == r) {
    tree[id].dp = b[l];
    return;
  }
  int mid = (l + r) >> 1;
  plant_tree(id << 1, l, mid);
  plant_tree(id << 1 | 1, mid + 1, r);
}
void pushdown(int id) {
  if (!tree[id].lazy) return;
  if (tree[id].left != tree[id].right) {
    tree[id << 1].lazy += tree[id].lazy;
    tree[id << 1].dp += tree[id].lazy;
    tree[id << 1 | 1].lazy += tree[id].lazy;
    tree[id << 1 | 1].dp += tree[id].lazy;
  }
  tree[id].lazy = 0;
}
void update_leaf(int id, int l, int r, int val) {
  if (tree[id].left == l && tree[id].right == r) {
    tree[id].dp += val;
    tree[id].lazy += val;
    return;
  }
  pushdown(id);
  int mid = (tree[id].left + tree[id].right) >> 1;
  if (r <= mid)
    update_leaf(id << 1, l, r, val);
  else if (mid < l)
    update_leaf(id << 1 | 1, l, r, val);
  else {
    update_leaf(id << 1, l, mid, val);
    update_leaf(id << 1 | 1, mid + 1, r, val);
  }
}
int query(int id, int pos) {
  if (tree[id].left == pos && tree[id].right == pos) {
    return tree[id].dp;
  }
  pushdown(id);
  int mid = (tree[id].left + tree[id].right) >> 1;
  if (pos <= mid)
    return query(id << 1, pos);
  else
    return query(id << 1 | 1, pos);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    where[a[i]] = i;
  }
  b[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (where[i] < where[i - 1])
      b[i] = b[i - 1] + 1;
    else
      b[i] = b[i - 1];
  }
  plant_tree(1, 1, n);
  int q;
  scanf("%d", &q);
  while (q--) {
    int ty;
    scanf("%d", &ty);
    if (ty == 1) {
      int x, y;
      scanf("%d %d", &x, &y);
      int r1 = query(1, x);
      int r2 = query(1, y);
      int ans = r2 - r1 + 1;
      printf("%d\n", ans);
    } else if (ty == 2) {
      int x, y;
      scanf("%d %d", &x, &y);
      if (a[x] + 1 == a[y]) {
        if (a[x] != 1 && where[a[x] - 1] > x && where[a[x] - 1] < y) {
          update_leaf(1, a[x], n, -1);
        }
        update_leaf(1, a[y], n, +1);
        if (a[y] != n && where[a[y] + 1] > x && where[a[y] + 1] < y) {
          update_leaf(1, a[y] + 1, n, -1);
        }
      } else if (a[x] == a[y] + 1) {
        if (a[y] != 1 && where[a[y] - 1] > x && where[a[y] - 1] < y) {
          update_leaf(1, a[y], n, +1);
        }
        update_leaf(1, a[x], n, -1);
        if (a[x] != n && where[a[x] + 1] > x && where[a[x] + 1] < y) {
          update_leaf(1, a[x] + 1, n, +1);
        }
      } else {
        if (a[x] != 1 && where[a[x] - 1] > x && where[a[x] - 1] < y) {
          update_leaf(1, a[x], n, -1);
        }
        if (a[x] != n && where[a[x] + 1] > x && where[a[x] + 1] < y) {
          update_leaf(1, a[x] + 1, n, +1);
        }
        if (a[y] != 1 && where[a[y] - 1] > x && where[a[y] - 1] < y) {
          update_leaf(1, a[y], n, +1);
        }
        if (a[y] != n && where[a[y] + 1] > x && where[a[y] + 1] < y) {
          update_leaf(1, a[y] + 1, n, -1);
        }
      }
      swap(where[a[x]], where[a[y]]);
      swap(a[x], a[y]);
    }
  }
}
