#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000;
const int inf = (int)1e9;
int n, q, data[maxn], pos[maxn], fenw[maxn];
inline int get(int r) {
  int ans = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) ans += fenw[r];
  return ans;
}
inline void inc(int r, int val) {
  for (; r < n; r |= r + 1) fenw[r] += val;
}
void refresh(int x) {
  if (x < 0 || x >= n - 1) return;
  inc(x, get(x - 1) - get(x));
  inc(x, pos[x] > pos[x + 1] ? 1 : 0);
}
int stress(int l, int r) {
  int ans = 0;
  for (int i = l; i < r; i++) ans += (pos[i] > pos[i + 1] ? 1 : 0);
  return ans + 1;
}
int main() {
  srand(time(0));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &data[i]), pos[--data[i]] = i;
  for (int i = 0; i < n; i++) refresh(data[i]);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int t, l, r;
    scanf("%d%d%d", &t, &l, &r), l--, r--;
    if (t == 1) {
      int ans = get(r - 1) - get(l - 1) + 1;
      printf("%d\n", ans);
    } else if (t == 2) {
      swap(pos[data[l]], pos[data[r]]);
      swap(data[l], data[r]);
      refresh(data[l]);
      refresh(data[l] - 1);
      refresh(data[r]);
      refresh(data[r] - 1);
    } else
      assert(false);
  }
  return 0;
}
