#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, p, x, y, i, temp, ind, cnt = 0;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  while (q--) {
    cin >> p >> x >> y;
    if (p == 2) {
      temp = a[x - 1];
      a[x - 1] = a[y - 1];
      a[y - 1] = temp;
    } else {
      cnt = 0;
      ind = x;
      while (ind <= y) {
        i = 0;
        while (i < n && ind <= y) {
          while (i < n && a[i] != ind && ind <= y) i++;
          if (i != n) ind++;
        }
        cnt++;
      }
      cout << cnt << endl;
    }
  }
}
