#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
const long long oo = 1e18;
map<int, int> Map;
int ans;
int n, a[N], pos[N];
int t[N];
inline int get(int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) res += t[r];
  return res;
}
inline int get(int l, int r) { return get(r) - get(l - 1); }
inline void upd(int x, int delta) {
  for (; x < N; x |= (x + 1)) t[x] += delta;
}
int deltas[2][2];
inline void change(int id, int to) {
  bool before[2];
  before[0] = pos[id] < pos[id - 1];
  before[1] = pos[id + 1] < pos[id];
  pos[id] = to;
  bool after[2];
  after[0] = pos[id] < pos[id - 1];
  after[1] = pos[id + 1] < pos[id];
  upd(id, deltas[before[0]][after[0]]);
  upd(id + 1, deltas[before[1]][after[1]]);
}
int main() {
  deltas[0][0] = 0;
  deltas[0][1] = 1;
  deltas[1][0] = -1;
  deltas[1][1] = 0;
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) pos[a[i]] = i;
  pos[n + 1] = n + 1;
  for (int i = 2; i <= n; ++i) {
    if (pos[i] < pos[i - 1]) upd(i, 1);
  }
  int q;
  cin >> q;
  while (q--) {
    int q_type, x, y;
    cin >> q_type >> x >> y;
    if (q_type == 1) {
      cout << get(x + 1, y) + 1 << "\n";
    } else {
      change(a[x], y);
      change(a[y], x);
      swap(a[x], a[y]);
    }
  }
  return 0;
}
