#include <bits/stdc++.h>
using namespace std;
int arr[300010], cc[300010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    cc[arr[i]] = i;
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int t, x, y;
    scanf("%d %d %d", &t, &x, &y);
    if (t == 1) {
      int ans = 1, p = cc[x];
      for (int j = x + 1; j <= y; j++) {
        if (cc[j] < p) {
          ans++;
        }
        p = cc[j];
      }
      printf("%d\n", ans);
    } else {
      x--;
      y--;
      swap(cc[arr[x]], cc[arr[y]]);
      swap(arr[x], arr[y]);
    }
  }
  return 0;
}
