#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int a[N], pos[N], c[N], is[N];
int n;
void add(int i, int k) {
  while (i <= n) {
    c[i] += k;
    i += i & -i;
  }
}
int query(int i) {
  int ans = 0;
  while (i) {
    ans += c[i];
    i -= i & -i;
  }
  return ans;
}
int main() {
  int i, j, m, op, L, R;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", a + i);
    pos[a[i]] = i;
  }
  is[1] = 0;
  for (i = 2; i <= n; i++) {
    if (pos[i] < pos[i - 1]) add(i, 1), is[i] = 1;
  }
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d%d", &op, &L, &R);
    if (op == 1)
      printf("%d\n", query(R) - query(L) + 1);
    else {
      int num1 = a[L], num2 = a[R];
      add(num1, -is[num1]);
      is[num1] = 0;
      add(num2, -is[num2]);
      is[num2] = 0;
      swap(a[L], a[R]);
      swap(pos[num1], pos[num2]);
      add(num1 + 1, -is[num1 + 1]);
      is[num1 + 1] = 0;
      add(num2 + 1, -is[num2 + 1]);
      is[num2 + 1] = 0;
      if (num1 > 1 && pos[num1] < pos[num1 - 1]) add(num1, 1), is[num1] = 1;
      if (num2 > 1 && pos[num2] < pos[num2 - 1]) add(num2, 1), is[num2] = 1;
      if (num1 < n && pos[num1 + 1] < pos[num1] && is[num1 + 1] == 0)
        add(num1 + 1, 1), is[num1 + 1] = 1;
      if (num2 < n && pos[num2 + 1] < pos[num2])
        add(num2 + 1, 1), is[num2 + 1] = 1;
    }
  }
  return 0;
}
