#include <bits/stdc++.h>
using namespace std;
const int N = 300500;
struct FenwickTree {
  int fen[N];
  void increase(int p, int v) {
    for (int i = p; i < N; i |= (i + 1)) fen[i] += v;
  }
  int getSum(int p) {
    int res = 0;
    for (int i = p; i >= 0; i = (i & (i + 1)) - 1) res += fen[i];
    return res;
  }
  int getSum(int l, int r) {
    if (l > r) return 0;
    return getSum(r) - (l ? getSum(l - 1) : 0);
  }
  void set(int p, int v) {
    int oldv = getSum(p, p);
    increase(p, v - oldv);
  }
};
int n, q, a[N], b[N];
FenwickTree sum;
void updateInfo(int x) {
  if (x - 1 >= 0) sum.set(x - 1, (b[x - 1] > b[x]));
  if (x < n - 1) sum.set(x, (b[x] > b[x + 1]));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
    b[a[i]] = i;
  }
  for (int i = 0; i < n; i++) updateInfo(i);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int p, x, y;
    scanf("%d%d%d", &p, &x, &y);
    x--;
    y--;
    if (p == 1) {
      int res = sum.getSum(x, y - 1);
      printf("%d\n", res + 1);
    } else {
      swap(b[a[x]], b[a[y]]);
      swap(a[x], a[y]);
      updateInfo(a[x]);
      updateInfo(a[y]);
    }
  }
  return 0;
}
