#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 60;
int a[300010], pos[300010];
int main() {
  int n, m, ch, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &ch, &x, &y);
    if (ch == 1) {
      for (int j = 1; j <= n; j++) pos[a[j]] = j;
      int pre = -1, ans = 1;
      for (int j = x; j <= y; j++) {
        if (pos[j] < pre) ans++;
        pre = pos[j];
      }
      printf("%d\n", ans);
    } else {
      swap(a[x], a[y]);
    }
  }
}
