#include <bits/stdc++.h>
using namespace std;
int pos[300010], a[300010], d[300010];
void insert(int x, int v) {
  if (!x) return;
  while (x < 300010) {
    d[x] += v;
    x += x & -x;
  }
}
int qq(int x) {
  int res = 0;
  while (x) {
    res += d[x];
    x -= x & -x;
  }
  return res;
}
int main() {
  int(n);
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); ++i) {
    scanf("%d", &(a[i]));
    pos[a[i]] = i;
  }
  for (int i = (1); i < (n); ++i) {
    if (pos[i] > pos[i + 1]) insert(i, 1);
  }
  int ___T, case_n = 1;
  scanf("%d ", &___T);
  while (___T-- > 0) {
    int ty, x, y;
    scanf("%d%d%d", &ty, &x, &y);
    if (ty == 1) {
      if (x == y)
        printf("1\n");
      else
        printf("%d\n", qq(y - 1) - qq(x - 1) + 1);
    } else {
      int xx = a[x];
      int yy = a[y];
      if (pos[xx] > pos[xx + 1]) insert(xx, -1);
      if (pos[xx - 1] > pos[xx]) insert(xx - 1, -1);
      if (yy != xx && yy != xx - 1 && pos[yy] > pos[yy + 1]) insert(yy, -1);
      if (yy - 1 != xx && yy - 1 != xx - 1 && pos[yy - 1] > pos[yy])
        insert(yy - 1, -1);
      swap(pos[xx], pos[yy]);
      swap(a[x], a[y]);
      if (pos[xx] > pos[xx + 1]) insert(xx, 1);
      if (pos[xx - 1] > pos[xx]) insert(xx - 1, 1);
      if (yy != xx && yy != xx - 1 && pos[yy] > pos[yy + 1]) insert(yy, 1);
      if (yy - 1 != xx && yy - 1 != xx - 1 && pos[yy - 1] > pos[yy])
        insert(yy - 1, 1);
    }
  }
  return 0;
}
