#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int n, q, a[maxn], b[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i] - 1] = i;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int p, l, r;
    cin >> p >> l >> r;
    l--;
    r--;
    if (p == 1) {
      int last = -1, ted = 0;
      for (int j = l; j <= r; j++) {
        if (b[j] > last)
          last = b[j];
        else {
          last = b[j];
          ted++;
        }
      }
      ted++;
      cout << ted << endl;
    } else {
      swap(a[l], a[r]);
      swap(b[a[l] - 1], b[a[r] - 1]);
    }
  }
  return 0;
}
