#include <bits/stdc++.h>
using namespace std;
int c[320000], N;
int pos[320000], a[320000], ad[320000];
void add(int x, int inc) {
  while (x <= N) {
    c[x] += inc;
    x += x & (-x);
  }
}
int query(int x) {
  int sum = 0;
  while (x) {
    sum += c[x];
    x -= x & (-x);
  }
  return sum;
}
int main() {
  int cas, L, R;
  while (scanf("%d", &N) != EOF) {
    for (int i = 1; i <= N; i++) {
      scanf("%d", &a[i]);
      pos[a[i]] = i;
    }
    memset(c, 0, sizeof(c));
    ad[1] = 0;
    for (int i = 2; i <= N; i++) {
      if (pos[i] < pos[i - 1]) {
        add(i, 1);
        ad[i] = 1;
      } else
        ad[i] = 0;
    }
    int Q;
    scanf("%d", &Q);
    while (Q--) {
      scanf("%d%d%d", &cas, &L, &R);
      if (cas == 1) {
        printf("%d\n", query(R) - query(L) + 1);
      } else {
        int num1 = a[L], num2 = a[R];
        swap(a[L], a[R]);
        add(num1, -ad[num1]);
        ad[num1] = 0;
        add(num2, -ad[num2]);
        ad[num2] = 0;
        add(num1 + 1, -ad[num1 + 1]);
        ad[num1 + 1] = 0;
        add(num2 + 1, -ad[num2 + 1]);
        ad[num2 + 1] = 0;
        swap(pos[num1], pos[num2]);
        if (num1 > 1 && pos[num1] < pos[num1 - 1] && ad[num1] == 0)
          add(num1, ad[num1] = 1);
        if (num2 > 1 && pos[num2] < pos[num2 - 1] && ad[num2] == 0)
          add(num2, ad[num2] = 1);
        if (num1 + 1 <= N && pos[num1 + 1] < pos[num1] && ad[num1 + 1] == 0)
          add(num1 + 1, ad[num1 + 1] = 1);
        if (num2 + 1 <= N && pos[num2 + 1] < pos[num2] && ad[num2 + 1] == 0)
          add(num2 + 1, ad[num2 + 1] = 1);
      }
    }
  }
  return 0;
}
