#include <bits/stdc++.h>
using namespace std;
int N, M, Num[333333], P, X, Y;
int D[333333], Sum[333333];
void updata(int x, int add) {
  while (x <= N) {
    Sum[x] += add;
    x += x & (-x);
  }
}
int sum(int x) {
  int ret = 0;
  while (x >= 1) {
    ret += Sum[x];
    x -= x & (-x);
  }
  return ret;
}
int main() {
  scanf("%d", &N);
  for (int n = 1; n <= N; ++n) {
    scanf("%d", Num + n);
    D[Num[n]] = n;
  }
  D[N + 1] = N + 1;
  for (int n = 1; n <= N + 1; ++n)
    if (D[n - 1] > D[n]) updata(n, 1);
  scanf("%d", &M);
  while (M--) {
    scanf("%d%d%d", &P, &X, &Y);
    if (P == 1)
      printf("%d\n", sum(Y) - sum(X) + 1);
    else {
      int n1 = Num[X], n2 = Num[Y];
      int nowx1 = D[n1]<D[n1 - 1], nowx2 = D[n1]> D[n1 + 1];
      int nowy1 = D[n2]<D[n2 - 1], nowy2 = D[n2]> D[n2 + 1];
      swap(Num[X], Num[Y]);
      swap(D[n1], D[n2]);
      int newx1 = D[n1]<D[n1 - 1], newx2 = D[n1]> D[n1 + 1];
      int newy1 = D[n2]<D[n2 - 1], newy2 = D[n2]> D[n2 + 1];
      updata(n1, newx1 - nowx1);
      if (n1 + 1 != n2) updata(n1 + 1, newx2 - nowx2);
      updata(n2, newy1 - nowy1);
      if (n2 + 1 != n1) updata(n2 + 1, newy2 - nowy2);
    }
  }
  return 0;
}
