#include <bits/stdc++.h>
using namespace std;
int a[105], o[105], n;
int A(int c, int d) {
  int s = 0, i;
  while (c <= d) {
    for (i = 1; i <= n; i++)
      if (o[i] == c) c++;
    s++;
  }
  return s;
}
int main() {
  int i, m, b, c, d, t;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &b);
    a[b] = i;
    o[i] = b;
  }
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &b, &c, &d);
    if (b == 2) {
      t = o[c];
      o[c] = o[d];
      o[d] = t;
      t = a[o[c]];
      a[o[c]] = a[o[d]];
      a[o[d]] = t;
    } else {
      printf("%d\n", A(c, d));
    }
  }
  return 0;
}
