#include <bits/stdc++.h>
int a[101], b[101];
int main() {
  int n, i, q, x, y, k, t, s, ls;
  for (scanf("%d", &n), i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[a[i]] = i;
  }
  for (scanf("%d", &q), i = 0; i < q; i++) {
    scanf("%d%d%d", &k, &x, &y);
    if (k == 1) {
      for (s = 0, ls = 101, t = x; t <= y; t++) {
        if (b[t] < ls) s++;
        ls = b[t];
      }
      printf("%d\n", s);
    } else if (k == 2) {
      b[a[x]] = y;
      b[a[y]] = x;
      t = a[x];
      a[x] = a[y];
      a[y] = t;
    }
  }
  return 0;
}
