#include <bits/stdc++.h>
using namespace std;
vector<int> fenv;
int sum(int r) {
  int ans = 0;
  while (r >= 0) {
    ans += fenv[r];
    r = (r & (r + 1)) - 1;
  }
  return ans;
}
int sum(int l, int r) { return sum(r) - sum(l - 1); }
void inc(int i, int val) {
  while (i < fenv.size()) {
    fenv[i] += val;
    i = i | (i + 1);
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> perm(n);
  for (int i = 0; i < n; ++i) {
    cin >> perm[i];
    --perm[i];
  }
  vector<int> pos(n);
  for (int i = 0; i < n; ++i) pos[perm[i]] = i;
  fenv.assign(n - 1, 0);
  for (int i = 0; i < n - 1; ++i)
    if (pos[i] > pos[i + 1]) inc(i, 1);
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int r, x, y;
    cin >> r >> x >> y;
    --x, --y;
    if (r == 1)
      cout << sum(x, y - 1) + 1 << endl;
    else {
      if (perm[x] > 0 && x <= pos[perm[x] - 1] && y >= pos[perm[x] - 1] &&
          perm[x] - 1 != perm[y])
        inc(perm[x] - 1, -1);
      if (perm[x] < n - 1 && x <= pos[perm[x] + 1] && y >= pos[perm[x] + 1])
        inc(perm[x], 1);
      if (perm[y] > 0 && x <= pos[perm[y] - 1] && y >= pos[perm[y] - 1] &&
          perm[y] - 1 != perm[x])
        inc(perm[y] - 1, 1);
      if (perm[y] < n - 1 && x <= pos[perm[y] + 1] && y >= pos[perm[y] + 1])
        inc(perm[y], -1);
      pos[perm[x]] = y;
      pos[perm[y]] = x;
      swap(perm[x], perm[y]);
    }
  }
  return 0;
}
