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