#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 15;
int sum[N];
int inverse[N];
void update(int *pen, int ind, int add) {
  while (ind < N) pen[ind] += add, ind += ind & (-ind);
}
int query(int *pen, int ind) {
  int ret = 0;
  while (ind) ret += pen[ind], ind = ind & (ind - 1);
  return ret;
}
int cur[N];
int a[N];
int get(int x, int n) {
  int l = x, r = n, mid;
  int u = query(inverse, x - 1), v;
  while (l < r) {
    mid = (l + r) / 2;
    v = query(inverse, mid);
    if (v - u > 0) {
      r = mid;
    } else
      l = mid + 1;
  }
  return l;
}
void INupdate(int u, int v, int n, int add) {
  set<int> s;
  set<int>::iterator it;
  if (u - 1 > 0 && cur[u - 1] > cur[u]) s.insert(u - 1);
  if (u + 1 <= n && cur[u] > cur[u + 1]) s.insert(u);
  if (v - 1 > 0 && cur[v - 1] > cur[v]) s.insert(v - 1);
  if (v + 1 <= n && cur[v] > cur[v + 1]) s.insert(v);
  for (it = s.begin(); it != s.end(); ++it) update(inverse, *it, add);
}
int main() {
  int n, i;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    cur[a[i]] = i;
  }
  for (i = 1; i < n; ++i) {
    if (cur[i] > cur[i + 1]) update(inverse, i, 1);
  }
  int pos = 1, npos;
  while (pos <= n) {
    npos = get(pos, n);
    update(sum, npos, 1);
    pos = npos + 1;
  }
  int q, type, x, y, t, nt, ind;
  cin >> q;
  set<int> s;
  set<int>::iterator it;
  while (q--) {
    scanf("%d%d%d", &type, &x, &y);
    if (type == 1) {
      pos = get(y, n);
      printf("%d\n", query(inverse, y - 1) - query(inverse, x - 1) + 1);
    } else {
      swap(a[x], a[y]);
      int u = a[x], v = a[y];
      INupdate(u, v, n, -1);
      cur[a[x]] = x, cur[a[y]] = y;
      INupdate(u, v, n, 1);
    }
  }
}
