#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int c[N];
int a[N], p[N];
int lowbit(int x) { return x & (-x); }
int getsum(int x) {
  int sum = 0;
  while (x) {
    sum += c[x];
    x -= lowbit(x);
  }
  return sum;
}
void up(int x, int num) {
  while (x < N) {
    c[x] += num;
    x += lowbit(x);
  }
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    p[a[i]] = i;
  }
  for (i = 2; i <= n; i++) {
    if (p[i] < p[i - 1]) up(i, 1);
  }
  int m;
  scanf("%d", &m);
  while (m--) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    if (x == 1)
      printf("%d\n", getsum(z) - getsum(y) + 1);
    else {
      int yy = a[y], zz = a[z];
      if (p[yy] < p[yy - 1]) up(yy, -1);
      if (yy < n && p[yy] > p[yy + 1]) up(yy + 1, -1);
      if (zz - 1 != yy && p[zz] < p[zz - 1]) up(zz, -1);
      if (zz + 1 != yy && zz < n && p[zz] > p[zz + 1]) up(zz + 1, -1);
      p[yy] = z;
      p[zz] = y;
      a[y] = zz;
      a[z] = yy;
      if (p[yy] < p[yy - 1]) up(yy, 1);
      if (yy < n && p[yy] > p[yy + 1]) up(yy + 1, 1);
      if (zz - 1 != yy && p[zz] < p[zz - 1]) up(zz, 1);
      if (zz + 1 != yy && zz < n && p[zz] > p[zz + 1]) up(zz + 1, 1);
    }
  }
  return 0;
}
