#include <bits/stdc++.h>
using namespace std;
int n;
int a[300010];
int b[300010];
int q;
int que[100010][3];
struct Tree {
  int l, r;
  int a, b;
} tree[300010 * 5];
void Build(int l, int r, int ss) {
  tree[ss].l = l;
  tree[ss].r = r;
  tree[ss].b = 0;
  if (l == r) {
    tree[ss].a = 1;
    return;
  }
  int mid = (l + r) / 2;
  Build(l, mid, ss * 2);
  Build(mid + 1, r, ss * 2 + 1);
  tree[ss].a = tree[ss * 2].a + tree[ss * 2 + 1].a -
               (b[tree[ss * 2].r] < b[tree[ss * 2 + 1].l]);
}
void Update(int l, int r, int ss) {
  if (tree[ss].l == l && tree[ss].r == r) {
    return;
  }
  int mid = (tree[ss].l + tree[ss].r) / 2;
  if (r <= mid)
    Update(l, r, ss * 2);
  else if (l > mid)
    Update(l, r, ss * 2 + 1);
  tree[ss].a = tree[ss * 2].a + tree[ss * 2 + 1].a -
               (b[tree[ss * 2].r] < b[tree[ss * 2 + 1].l]);
}
int Find(int l, int r, int ss) {
  if (tree[ss].l == l && tree[ss].r == r) {
    return tree[ss].a;
  }
  int mid = (tree[ss].l + tree[ss].r) / 2;
  if (r <= mid)
    return Find(l, r, ss * 2);
  else if (l > mid)
    return Find(l, r, ss * 2 + 1);
  else
    return Find(l, mid, ss * 2) + Find(mid + 1, r, ss * 2 + 1) -
           (b[mid] < b[mid + 1]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[a[i]] = i;
  }
  Build(1, n, 1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    for (int j = 0; j < 3; j++) scanf("%d", &que[i][j]);
  }
  for (int i = 1; i <= q; i++) {
    if (que[i][0] == 2) {
      int u, v;
      u = que[i][1];
      v = que[i][2];
      swap(b[a[u]], b[a[v]]);
      swap(a[u], a[v]);
      Update(a[u], a[u], 1);
      Update(a[v], a[v], 1);
    } else {
      int x, y;
      x = que[i][1], y = que[i][2];
      printf("%d\n", Find(x, y, 1));
    }
  }
}
