#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:640000000")
using namespace std;
const long long INF = (1e15) + 4;
const int N = 3e5 + 5;
int a[N];
int f[N];
int p[N];
int b[N];
int n;
int len;
int get(int r) {
  int ans = 0;
  for (int i = r; i >= 0; i = (i & (i + 1)) - 1) ans += f[i];
  return ans;
}
void upd(int r, int val) {
  for (int i = r; i < n; i = (i | (i + 1))) f[i] += val;
}
int get_sum(int l, int r) { return get(r) - (l > 0 ? get(l - 1) : 0); }
void calc(int el) {
  if (el < 0) return;
  if (el >= n) return;
  if (el + 1 < n) {
    if (!b[el] && a[el] > a[el + 1]) {
      b[el] = true;
      upd(el, +1);
    }
    if (b[el] && a[el] < a[el + 1]) {
      b[el] = false;
      upd(el, -1);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int first;
    scanf("%d", &first);
    first--;
    a[first] = i;
    p[i] = first;
  }
  for (int i = 0; i < n; i++) {
    calc(p[i]);
  }
  int m;
  scanf("%d", &m);
  int last = n + 1;
  for (int i = 0; i < m; i++) {
    int type, l, r;
    scanf("%d %d %d", &type, &l, &r);
    l--;
    r--;
    if (type == 1) {
      printf("%d\n", get_sum(l, r - 1) + 1);
    } else {
      swap(p[l], p[r]);
      swap(a[p[l]], a[p[r]]);
      calc(p[l]);
      calc(p[r]);
      calc(p[l] - 1);
      calc(p[r] - 1);
    }
  }
  return 0;
}
