#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, d, p[N], ind[N], seg[4 * N];
void upd(int x, int val, int s = 0, int e = n, int id = 1) {
  if (x >= e || x < s) return;
  if (e - s == 1) {
    ind[s] = val;
    return;
  }
  int mid = (s + e) / 2;
  upd(x, val, s, mid, 2 * id);
  upd(x, val, mid, e, 2 * id + 1);
  seg[id] = seg[2 * id] + seg[2 * id + 1] + (ind[mid - 1] > ind[mid]);
}
int las = -1;
int get(int l, int r, int s = 0, int e = n, int id = 1) {
  if (r <= s || e <= l) return 0;
  if (l <= s && e <= r) {
    int ret = las > ind[s];
    las = ind[e - 1];
    return seg[id] + ret;
  }
  int mid = (s + e) / 2;
  return get(l, r, s, mid, 2 * id) + get(l, r, mid, e, 2 * id + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
    upd(p[i], i);
  }
  int q;
  cin >> q;
  for (int _ = 0; _ < q; _++) {
    int t, x, y;
    cin >> t >> x >> y;
    x--;
    y--;
    if (t == 1)
      las = -1, cout << get(x, y + 1) + 1 << "\n";
    else {
      int p1 = p[x], p2 = p[y];
      swap(p[x], p[y]);
      upd(p1, y);
      upd(p2, x);
    }
  }
}
