#include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-11;
const double pi = acos(-1.0);
const int N = 300100;
int a[N];
int inv[N];
int main() {
  int n;
  scanf("%d", &n);
  for (long long i = 0; i < n; i++) {
    scanf("%d", a + i);
    --a[i];
    inv[a[i]] = i;
  }
  int q;
  scanf("%d", &q);
  int f, x, y;
  for (long long qq = 0; qq < q; qq++) {
    scanf("%d%d%d", &f, &x, &y);
    --x, --y;
    if (f == 1) {
      int m = 1;
      for (long long t = x + 1; t <= y; t++) {
        if (inv[t] < inv[t - 1]) ++m;
      }
      printf("%d\n", m);
    } else {
      swap(inv[a[x]], inv[a[y]]);
      swap(a[x], a[y]);
    }
  }
  return 0;
}
