#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")
string problem_name = "a";
void init() { freopen((problem_name + ".in").c_str(), "rt", stdin); }
int p[300100];
int pos[300100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    pos[p[i]] = i;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    if (t == 2) {
      swap(p[x], p[y]);
      swap(pos[p[x]], pos[p[y]]);
    } else {
      int res = 0;
      int pr = -1;
      for (int i = x; i <= y; i++) {
        if (pos[i] < pr) {
          res++;
        }
        pr = pos[i];
      }
      printf("%d\n", res + 1);
    }
  }
  return 0;
}
