#include <bits/stdc++.h>
using namespace std;
void qs(int *a, int l, int r) {
  int i = l;
  int j = r;
  int y, p = a[(l + r) >> 1];
  do {
    while (a[i] < p && i < r) i++;
    while (a[j] > p && j > l) j--;
    if (i <= j) {
      y = a[i];
      a[i] = a[j];
      a[j] = y;
      i++;
      j--;
    }
  } while (i <= j);
  if (i < r) qs(a, i, r);
  if (j > l) qs(a, l, j);
}
int main() {
  int n, q, p, x, y, k, t;
  scanf("%d", &n);
  int *a = new int[n + 1];
  int *b = new int[n + 1];
  for (int i = (int)1; i < (int)n + 1; i++) {
    scanf("%d", &a[i]);
    b[a[i]] = i;
  }
  scanf("%d", &q);
  for (int i = 0; i < (int)q; i++) {
    scanf("%d %d %d", &p, &x, &y);
    if (p == 1) {
      k = 1;
      while (++x <= y)
        if (!(b[x] > b[x - 1])) k++;
      printf("%d\n", k);
    } else {
      b[a[x]] = y;
      b[a[y]] = x;
      t = a[x];
      a[x] = a[y];
      a[y] = t;
    }
  }
  return 0;
}
