#include <bits/stdc++.h>
using namespace std;
int n;
int a[330000];
int p[330000];
int t[330000];
void add(int x, int c) {
  while (x <= n) {
    t[x] += c;
    x += x & -x;
  }
}
int query(int x) {
  int ret = 0;
  while (x) {
    ret += t[x];
    x -= x & -x;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[a[i]] = i;
  }
  for (int i = 1; i < n; i++) {
    if (p[i] > p[i + 1]) add(i, 1);
  }
  int q;
  cin >> q;
  while (q--) {
    int ope, x, y;
    cin >> ope >> x >> y;
    if (ope == 1) {
      cout << query(y - 1) - query(x - 1) + 1 << endl;
    } else {
      if (x == y) continue;
      if (a[x] > a[y]) swap(x, y);
      if (a[x] != n && p[a[x]] > p[a[x] + 1]) add(a[x], -1);
      if (a[y] != n && p[a[y]] > p[a[y] + 1]) add(a[y], -1);
      if (a[x] != 1 && p[a[x] - 1] > p[a[x]]) add(a[x] - 1, -1);
      if (a[x] != a[y] - 1 && a[y] != 1 && p[a[y] - 1] > p[a[y]])
        add(a[y] - 1, -1);
      swap(a[x], a[y]);
      p[a[x]] = x;
      p[a[y]] = y;
      if (a[x] != n && p[a[x]] > p[a[x] + 1]) add(a[x], 1);
      if (a[y] != n && p[a[y]] > p[a[y] + 1]) add(a[y], 1);
      if (a[x] - 1 != a[y] && a[x] != 1 && p[a[x] - 1] > p[a[x]])
        add(a[x] - 1, 1);
      if (a[y] != 1 && p[a[y] - 1] > p[a[y]]) add(a[y] - 1, 1);
    }
  }
  return 0;
}
