#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int a, vis[111], id[111];
int main() {
  int n, i, m, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a), id[a] = i;
  scanf("%d", &m);
  while (m--) {
    int x, y, z;
    scanf("%d%d%d", &z, &x, &y);
    if (z == 2) {
      int p1, p2;
      for (i = 1; i <= n; i++) {
        if (x == id[i]) p1 = i;
        if (y == id[i]) p2 = i;
      }
      swap(id[p1], id[p2]);
    } else {
      int cnt = 0, last = 1111;
      for (i = x; i <= y; i++) {
        if (id[i] < last) cnt++;
        last = id[i];
      }
      printf("%d\n", cnt);
    }
  }
}
