#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5, oo = MAXN + 1;
int n, p, x, y, q, a[MAXN], pos[MAXN], len[MAXN];
int query(int a, int b) {
  int ans = 0;
  while (a <= b) {
    a = a + len[pos[a]];
    ++ans;
  }
  return ans;
}
void build() {
  for (int i = 0; i < n; ++i) pos[a[i]] = i;
  for (int i = n - 1; i >= 0; --i) {
    if (a[i] == n || pos[a[i]] > pos[a[i] + 1])
      len[i] = 1;
    else
      len[i] = 1 + len[pos[a[i] + 1]];
  }
}
void mswap(int l, int r) {
  swap(a[l], a[r]);
  build();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  build();
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> p >> x >> y;
    if (p == 1)
      cout << query(x, y) << '\n';
    else
      mswap(x - 1, y - 1);
  }
  return 0;
}
