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