#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000500;
const int infi = (1 << 30);
const long long infl = (1LL << 62);
const double eps = 1e-9;
const long long mod = 1000000007LL;
const unsigned long long hash_base = 257LL;
const double pi = acos(-1.0);
int n, q, t, cx, cy, ans;
int a[105], b[105];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int first;
    cin >> first;
    --first;
    a[first] = i;
    b[i] = first;
  }
  cin >> q;
  while (q--) {
    cin >> t >> cx >> cy;
    --cx;
    --cy;
    if (t == 1) {
      ans = 1;
      while (cx < cy) {
        if (a[cx] > a[cx + 1]) ans++;
        cx++;
      }
      cout << ans << endl;
    } else {
      swap(a[b[cx]], a[b[cy]]);
      swap(b[cx], b[cy]);
    }
  }
  return 0;
}
