#include <bits/stdc++.h>
using namespace std;
struct FenwickTree {
  int c[1100000], n;
  void init(int _n) {
    n = _n;
    memset(c, 0, sizeof(int) * (n + 1));
  }
  void add(int x, int val) {
    while (x <= n) {
      c[x] += val;
      x += (x & (-x));
    }
  }
  int sum(int x) {
    int res = 0;
    while (x) {
      res += c[x];
      x -= (x & (-x));
    }
    return res;
  }
} ft;
int n, pos[1100000], a[1100000];
int sgn(int x) { return x > 0 ? 1 : -1; }
void cao(int x, int y) {
  int v = a[x], w;
  if (v != 1) {
    w = pos[v - 1];
    int d = sgn(y - w) - sgn(x - w);
    ft.add(v, (-d) >> 1);
  }
  if (v != n) {
    w = pos[v + 1];
    int d = sgn(y - w) - sgn(x - w);
    ft.add(v + 1, d >> 1);
  }
}
void cao1(int x, int y) {
  int v = a[x], w;
  if (v != 1) {
    w = pos[v - 1];
    int d = sgn(y - w) - sgn(x - w);
    ft.add(v, (-d) >> 1);
  }
}
void cao2(int x, int y) {
  int v = a[x], w;
  if (v != n) {
    w = pos[v + 1];
    int d = sgn(y - w) - sgn(x - w);
    ft.add(v + 1, d >> 1);
  }
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), pos[a[i]] = i;
    ft.init(n);
    ft.add(1, 1);
    for (int i = 2; i <= n; i++) {
      if (pos[i] < pos[i - 1]) ft.add(i, 1);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
      int op, l, r;
      scanf("%d%d%d", &op, &l, &r);
      if (op == 1) {
        printf("%d\n", ft.sum(r) - ft.sum(l) + 1);
      } else {
        if (abs(a[l] - a[r]) > 1) {
          cao(l, r);
          cao(r, l);
        } else {
          if (a[l] > a[r]) swap(l, r);
          if (r > l)
            ft.add(a[r], 1);
          else
            ft.add(a[r], -1);
          cao1(l, r);
          cao2(r, l);
        }
        swap(a[l], a[r]);
        swap(pos[a[l]], pos[a[r]]);
      }
    }
  }
  return 0;
}
