#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  unsigned long long n = 0;
  cin >> n;
  vector<unsigned long> beavers(n);
  for (unsigned long i = 0; i < beavers.size(); i++) {
    cin >> beavers[i];
  }
  unsigned long long num_queries = 0;
  cin >> num_queries;
  for (unsigned long q = 0; q < num_queries; q++) {
    unsigned long p = 0, x = 0, y = 0;
    cin >> p >> x >> y;
    if (p == 1) {
      unsigned long cost = 0;
      for (unsigned long looking_for = x; looking_for <= y;) {
        for (unsigned long i = 0; i < beavers.size(); i++) {
          if (beavers[i] != looking_for) continue;
          looking_for++;
        }
        cost++;
      }
      cout << cost << endl;
    } else {
      x--, y--;
      unsigned long swap = beavers[x];
      beavers[x] = beavers[y];
      beavers[y] = swap;
    }
  }
  return 0;
}
