#include <bits/stdc++.h>
using namespace std;
int po[110], a[110];
int main() {
  int n, i, q;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    po[a[i]] = i;
  }
  scanf("%d", &q);
  int x, y, t;
  while (q--) {
    scanf("%d%d%d", &t, &x, &y);
    if (t == 1) {
      int ans = 0, tt = x;
      while (1) {
        if (tt == y) {
          ans++;
          break;
        }
        if (po[tt + 1] < po[tt]) ans++;
        tt++;
      }
      printf("%d\n", ans);
    } else {
      int tmp = a[x];
      a[x] = a[y];
      a[y] = tmp;
      po[a[x]] = x;
      po[a[y]] = y;
    }
  }
  return 0;
}
