#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, a[N], pos[N], fen[N];
void add(int p, int x) {
  for (p++; p < N; p += p & -p) fen[p] += x;
}
int get(int p) {
  int ans = 0;
  for (; p; p -= p & -p) ans += fen[p];
  return ans;
}
void readInput() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
}
void prep() {
  for (int i = 0; i < n; i++) pos[--a[i]] = i;
  for (int i = 0; i < n; i++) add(a[i], i >= pos[a[i] + 1]);
}
void writeOutput() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    x--, y--;
    if (t & 1)
      cout << get(y) - get(x) + 1 << endl;
    else {
      vector<int> vec;
      for (auto p : {x, y}) {
        vec.push_back(p);
        if (a[p]) vec.push_back(pos[a[p] - 1]);
      }
      sort(vec.begin(), vec.end());
      vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
      for (auto p : vec) add(a[p], -(p >= pos[a[p] + 1]));
      swap(a[x], a[y]), swap(pos[a[x]], pos[a[y]]);
      for (auto p : vec) add(a[p], p >= pos[a[p] + 1]);
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  readInput(), prep(), writeOutput();
  return 0;
}
