#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 sq[300000];
int bs = 512;
int n;
int recalc(int cur) {
  int res = 0;
  for (int i = cur * bs + 1; i < (cur + 1) * (bs); i++) {
    if (i >= n) break;
    if (pos[i] < pos[i - 1]) res++;
  }
  sq[cur] = res;
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
    pos[p[i]] = i;
  }
  for (int i = 0; i < 1000; i++) recalc(i);
  int q;
  scanf("%d", &q);
  while (q--) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    x--;
    y--;
    if (t == 2) {
      swap(p[x], p[y]);
      swap(pos[p[x]], pos[p[y]]);
      recalc(p[x] / bs);
      recalc(p[y] / bs);
    } else {
      int res = 0;
      int pr = -1;
      for (int i = x; i <= y;) {
        if (i % bs == 0 && i + bs - 1 <= y) {
          if (i > x) res += pos[i] < pos[i - 1];
          res += sq[i / bs];
          i += bs;
        } else {
          if (i > x) res += pos[i] < pos[i - 1];
          i++;
        }
      }
      printf("%d\n", res + 1);
    }
  }
  return 0;
}
