#include <bits/stdc++.h>
const int maxN = 128;
int A[maxN];
int N;
int B[maxN];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", A + i);
  for (int i = 1; i <= N; i++) B[A[i]] = i;
  int q, p, x, y;
  scanf("%d", &q);
  int res, t;
  while ((q--) > 0) {
    scanf("%d %d %d", &p, &x, &y);
    if (p == 1) {
      res = 1;
      for (t = x + 1; t <= y; t++) {
        if (B[t] < B[t - 1]) {
          res++;
        }
      }
      printf("%d\n", res);
    } else if (p == 2) {
      t = A[x];
      A[x] = A[y];
      A[y] = t;
      B[A[x]] = x;
      B[A[y]] = y;
    }
  }
  return 0;
}
