#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long INF64 = (long long)1e18;
const long double eps = 1e-9;
const long double pi = 3.14159265358979323846;
int nu[301000];
int loc[301000];
int arr[1500010];
int ans(int ss, int ee, int s, int e, int now) {
  if (ss == s && ee == e) return arr[now];
  if (ss == ee) return 1;
  int mid = (s + e) / 2;
  if (ee <= mid) return ans(ss, ee, s, mid, now + now);
  if (ss > mid) return ans(ss, ee, mid + 1, e, now + now + 1);
  int ta = ans(ss, mid, s, mid, now + now);
  int tb = ans(mid + 1, ee, mid + 1, e, now + now + 1);
  int aaans = ta + tb;
  if (loc[mid] < loc[mid + 1]) aaans--;
  return aaans;
}
void build(int ss, int ee, int now) {
  if (ss == ee) {
    arr[now] = 1;
    return;
  }
  int mid = (ss + ee) / 2;
  build(ss, mid, now + now);
  build(mid + 1, ee, now + now + 1);
  arr[now] = arr[now + now] + arr[now + now + 1];
  if (loc[mid] < loc[mid + 1]) arr[now]--;
}
void add(int pos, int ss, int ee, int now) {
  if (ss == ee) return;
  int mid = (ss + ee) / 2;
  if (pos <= mid) add(pos, ss, mid, now + now);
  if (pos > mid) add(pos, mid + 1, ee, now + now + 1);
  arr[now] = arr[now + now] + arr[now + now + 1];
  if (loc[mid] < loc[mid + 1]) arr[now]--;
}
int main() {
  int i;
  int n, qn;
  int q, a, b;
  while (cin >> n) {
    for (i = 0; i < n; i++) {
      cin >> nu[i];
      nu[i]--;
      loc[nu[i]] = i;
    }
    build(0, n - 1, 1);
    cin >> qn;
    while (qn--) {
      cin >> q >> a >> b;
      a--, b--;
      if (q == 2) {
        swap(loc[nu[a]], loc[nu[b]]);
        swap(nu[a], nu[b]);
        add(nu[a], 0, n - 1, 1);
        add(nu[b], 0, n - 1, 1);
      } else {
        printf("%d\n", ans(min(a, b), max(a, b), 0, n - 1, 1));
      }
    }
  }
  return 0;
}
