#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 11;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
long long read() {
  long long x = 0, f = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long a[MAXN], pos[MAXN];
bool block[111], vis[111];
bool check(int st, int ed) {
  for (register int i = st; i <= ed; i++)
    if (vis[a[i]] == 0) return 0;
  return 1;
}
int findlastmin(int st, int ed) {
  set<int> s;
  for (register int i = st; i <= ed; i++) {
    if (!vis[a[i]]) s.insert(a[i]);
  }
  if (s.size()) return *s.begin();
  return -1;
}
int main() {
  int n, q;
  while (cin >> n) {
    for (register int i = 1; i <= n; i++) {
      a[i] = read();
      pos[a[i]] = i;
    }
    q = read();
    for (register int i = 1; i <= q; i++) {
      int x = read();
      int y = read();
      int z = read();
      if (x == 1) {
        long long res = 0;
        long long last = y - 1;
        while (1) {
          if (last >= z) break;
          res++;
          for (register int i = 1; i <= n; i++) {
            if (last + 1 == a[i]) last++;
          }
        }
        printf("%lld\n", (long long)(res));
      } else {
        int yy = a[y], zz = a[z];
        swap(a[y], a[z]);
        swap(pos[yy], pos[zz]);
      }
    }
  }
  return 0;
}
