#include <bits/stdc++.h>
using namespace std;
int n, m;
int ar[300005];
int ind[300005];
int tree[4 * 300005];
int Build(int cx, int cy, int pos) {
  if (cx == cy) return tree[pos] = (ind[cx] < ind[cx - 1]);
  int mid = (cx + cy) >> 1;
  return tree[pos] = Build(cx, mid, pos * 2) + Build(mid + 1, cy, pos * 2 + 1);
}
int Update(int cx, int cy, int q, int val, int pos) {
  if (q < cx || cy < q) return tree[pos];
  if (cx == cy) return tree[pos] = val;
  int mid = (cx + cy) >> 1;
  return tree[pos] = Update(cx, mid, q, val, pos * 2) +
                     Update(mid + 1, cy, q, val, pos * 2 + 1);
}
int Query(int cx, int cy, int qx, int qy, int pos) {
  if (qy < cx || cy < qx) return 0;
  if (qx <= cx && cy <= qy) return tree[pos];
  int mid = (cx + cy) >> 1;
  return Query(cx, mid, qx, qy, pos * 2) +
         Query(mid + 1, cy, qx, qy, pos * 2 + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    ind[ar[i]] = i;
  }
  Build(1, n, 1);
  scanf("%d", &m);
  ind[n + 1] = n + 1;
  for (int i = 0, p, x, y; i < m; i++) {
    scanf("%d%d%d", &p, &x, &y);
    if (p == 1)
      printf("%d\n", Query(1, n, x + 1, y, 1) + 1);
    else {
      int t1 = ar[x], t2 = ar[y];
      if (t1 + 1 == t2) {
        Update(1, n, t1, y < ind[t1 - 1], 1);
        Update(1, n, t2, y > x, 1);
        Update(1, n, t2 + 1, x > ind[t2 + 1], 1);
      } else {
        Update(1, n, t1, y < ind[t1 - 1], 1);
        Update(1, n, t1 + 1, y > ind[t1 + 1], 1);
        Update(1, n, t2, x < ind[t2 - 1], 1);
        Update(1, n, t2 + 1, x > ind[t2 + 1], 1);
      }
      swap(ar[x], ar[y]);
      swap(ind[t1], ind[t2]);
    }
  }
  return 0;
}
