#include <bits/stdc++.h>
using namespace std;
int id[110];
int n, m, k, x, y;
map<int, int> mp;
int fun(int &x, int &y) {
  int ans = 1;
  for (int i = x + 1; i <= y; i++) {
    if (mp[i] < mp[i - 1]) ans++;
  }
  return ans;
}
void h(int x, int y) {
  int nx = id[x];
  int ny = id[y];
  mp[nx] = y;
  mp[ny] = x;
  swap(id[x], id[y]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> id[i];
    mp[id[i]] = i;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> k >> x >> y;
    if (2 == k) {
      h(x, y);
      continue;
    }
    cout << fun(x, y) << endl;
  }
  return 0;
}
