#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
int A[105];
int f[105];
int main() {
  int n, i, p, x, y;
  cin >> n;
  for (i = 0; i < n; i++) cin >> A[i], f[A[i]] = i;
  int q;
  cin >> q;
  while (q--) {
    scanf("%d %d %d", &p, &x, &y);
    if (p == 1) {
      int res = 0;
      while (x <= y) {
        while (x < y && f[x + 1] > f[x]) x++;
        x++;
        res++;
      }
      printf("%d\n", res);
    } else {
      x--;
      y--;
      int L = A[x], R = A[y];
      swap(A[x], A[y]);
      f[L] = y;
      f[R] = x;
    }
  }
}
