#include <bits/stdc++.h>
using namespace std;
int n, nevents;
int p[300000];
int inv[300000];
int val[1 << 19];
int get(int x) {
  ++x;
  int ret = 0;
  while (x != 0) {
    ret += val[x];
    x -= x & -x;
  }
  return ret;
}
void update(int x, int by) {
  ++x;
  while (x != 1 << 19) {
    val[x] += by;
    x += x & -x;
  }
}
void run(int casenr) {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &p[i]);
    --p[i];
  }
  for (int i = (0); i < (n); ++i) inv[p[i]] = i;
  memset(val, 0, sizeof(val));
  for (int i = (0); i < (n - 1); ++i)
    if (inv[i + 1] < inv[i]) update(i, +1);
  scanf("%d", &nevents);
  for (int e = (0); e < (nevents); ++e) {
    int type, x, y;
    scanf("%d%d%d", &type, &x, &y);
    --x, --y;
    if (type == 1) {
      int ans = get(y - 1) - get(x - 1) + 1;
      printf("%d\n", ans);
    }
    if (type == 2) {
      int a = p[x], b = p[y];
      int lst[4], nlst = 0;
      if (a - 1 >= 0) lst[nlst++] = a - 1;
      if (a + 1 < n) lst[nlst++] = a;
      if (b - 1 >= 0) lst[nlst++] = b - 1;
      if (b + 1 < n) lst[nlst++] = b;
      sort(lst, lst + nlst);
      for (int i = (0); i < (nlst); ++i)
        if (i == 0 || lst[i] != lst[i - 1]) {
          int xi = lst[i], xj = xi + 1, pi = inv[xi], pj = inv[xj],
              ni = pi == x   ? y
                   : pi == y ? x
                             : pi,
              nj = pj == x   ? y
                   : pj == y ? x
                             : pj;
          int delta = (nj < ni ? 1 : 0) - (pj < pi ? 1 : 0);
          if (delta != 0) update(xi, delta);
        }
      swap(p[x], p[y]);
      inv[p[x]] = x;
      inv[p[y]] = y;
    }
  }
}
int main() {
  run(1);
  return 0;
}
