#include <bits/stdc++.h>
using namespace std;
const int NMax = 301000, MMax = 200;
struct node {
  int size;
  int leftmost, rightmost;
} T[NMax * 4];
int N;
void insert(int a, int b, int first, int second, int p) {
  if (first == second) {
    T[p].leftmost = T[p].rightmost = b;
    return;
  }
  int mid = (first + second) >> 1;
  if (mid >= a)
    insert(a, b, first, mid, p * 2);
  else
    insert(a, b, mid + 1, second, p * 2 + 1);
  T[p].leftmost = T[p * 2].leftmost;
  T[p].rightmost = T[p * 2 + 1].rightmost;
  T[p].size = T[p * 2].size + T[p * 2 + 1].size;
  if (T[p * 2].rightmost > T[p * 2 + 1].leftmost) T[p].size++;
}
int calc(int a, int b, int first, int second, int p) {
  if (first == a && second == b) return T[p].size;
  int mid = (first + second) >> 1;
  if (mid >= b)
    return calc(a, b, first, mid, p * 2);
  else if (mid < a)
    return calc(a, b, mid + 1, second, p * 2 + 1);
  else {
    int ret = calc(a, mid, first, mid, p * 2) +
              calc(mid + 1, b, mid + 1, second, p * 2 + 1);
    if (T[p * 2].rightmost > T[p * 2 + 1].leftmost) ret++;
    return ret;
  }
}
int A[NMax];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    int first;
    scanf("%d", &first);
    insert(first, i, 1, N, 1);
    A[i] = first;
  }
  int Q;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int t, first, second;
    scanf("%d%d%d", &t, &first, &second);
    if (t == 1)
      printf("%d\n", calc(first, second, 1, N, 1) + 1);
    else {
      swap(A[first], A[second]);
      insert(A[first], first, 1, N, 1);
      insert(A[second], second, 1, N, 1);
    }
  }
  return 0;
}
