#include <bits/stdc++.h>
int p[110];
int pos[110];
void swap(int *p, int *q) {
  (*p) ^= (*q);
  (*q) ^= (*p);
  (*p) ^= (*q);
}
void change(int x, int y) {
  swap(&pos[p[x - 1]], &pos[p[y - 1]]);
  swap(&p[x - 1], &p[y - 1]);
}
void query(int x, int y) {
  int ans, cur;
  ans = 1;
  for (cur = y; cur > x; cur--) {
    if (pos[cur] < pos[cur - 1]) {
      ans++;
    }
  }
  printf("%d\n", ans);
}
int main() {
  int n, q, i, t, x, y;
  while (scanf("%d", &n) == 1) {
    for (i = 0; i < n; i++) {
      scanf("%d", &p[i]);
      pos[p[i]] = i;
    }
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
      scanf("%d%d%d", &t, &x, &y);
      if (t == 1) {
        query(x, y);
      } else {
        change(x, y);
      }
    }
  }
  return 0;
}
