#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  for (int(i) = 0; (i) < (((int)((t).size()))); ++(i)) s << t[i] << " ";
  return s;
}
void add(int *a, int n, int x) {
  for (; n < 400007; n |= n + 1) a[n] += x;
}
int sum(int *a, int n) {
  int s = 0;
  while (n >= 0) {
    s += a[n];
    n = (n & (n + 1)) - 1;
  }
  return s;
}
int sumbetween(int *a, int le, int ri) { return sum(a, ri) - sum(a, le - 1); }
int fen[400007], a[400007], pos[400007], val[400007];
void upd(int i) {
  if (pos[i + 1] < pos[i]) {
    if (val[i] != 1) {
      val[i] = 1;
      add(fen, i, 1);
    }
  } else {
    if (val[i] != 0) {
      val[i] = 0;
      add(fen, i, -1);
    }
  }
}
int main() {
  int(n);
  scanf("%d", &(n));
  for (int(i) = 1; (i) <= (n); ++(i)) {
    scanf("%d", a + i);
    pos[a[i]] = i;
  }
  for (int(i) = 1; (i) <= (n - 1); ++(i))
    if (pos[i + 1] < pos[i]) {
      val[i] = 1;
      add(fen, i, 1);
    }
  int(testow);
  scanf("%d", &(testow));
  while (testow--) {
    int(typ), (x), (y);
    scanf("%d %d %d", &(typ), &(x), &(y));
    if (typ == 1) {
      pisz(1 + sumbetween(fen, x, y - 1));
    } else {
      int A = a[x], B = a[y];
      pos[A] = y;
      pos[B] = x;
      a[x] = B;
      a[y] = A;
      upd(A);
      if (A > 1) upd(A - 1);
      upd(B);
      if (B > 1) upd(B - 1);
    }
  }
}
