#include <bits/stdc++.h>
using namespace std;
int n, q, a[1000000], loc[1000000], st[4000000];
int update(int root, int bas, int son, int x, int val) {
  if (x < bas or son < x) return st[root];
  if (bas == son) return st[root] = val;
  return st[root] = update(root * 2 + 0, bas + 0, (bas + son) / 2, x, val) +
                    update(root * 2 + 1, (bas + son) / 2 + 1, son, x, val);
}
int query(int root, int bas, int son, int x, int y) {
  if (son < x or y < bas) return 0;
  if (x <= bas and son <= y) return st[root];
  return query(root * 2 + 0, bas + 0, (bas + son) / 2, x, y) +
         query(root * 2 + 1, (bas + son) / 2 + 1, son, x, y);
}
void guncelle(int x) {
  update(1, 1, n, x, loc[x] > loc[x + 1]);
  update(1, 1, n, x - 1, loc[x - 1] > loc[x]);
}
int main() {
  int p, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[i] = x;
    loc[x] = i;
  }
  for (int i = 1; i <= n; i++) update(1, 1, n, i, loc[i] > loc[i + 1]);
  loc[n + 1] = n + 1;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d", &p, &x, &y);
    if (p == 1) {
      printf("%d\n", query(1, 1, n, x, y - 1) + 1);
    } else {
      swap(loc[a[x]], loc[a[y]]);
      swap(a[x], a[y]);
      guncelle(a[x]);
      guncelle(a[y]);
    }
  }
}
