#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int N = 111;
int n, a[N], first[N], ans, m, x, y, cmd;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int it = 1; it <= m; it++) {
    scanf("%d%d%d", &cmd, &x, &y);
    if (cmd == 2) swap(a[x], a[y]);
    if (cmd == 1) {
      memset(first, 0, sizeof(first));
      for (int i = 1; i <= n; i++) {
        first[a[i]] = first[a[i] - 1];
        if (first[a[i]] == 0) first[a[i]] = i;
      }
      first[x - 1] = -1;
      ans = 0;
      for (int i = x; i <= y; i++)
        if (first[i] != first[i - 1]) ans++;
      printf("%d\n", ans);
    }
  }
}
