#include <bits/stdc++.h>
using namespace std;
int dx4[] = {-1, 0, 1, 0};
int dy4[] = {0, 1, 0, -1};
int dx8[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
bool AreEqual(double a, double b) { return (fabs(a - b) < 1e-10); }
template <class T>
bool GetNr(T &_value) {
  T _sign = 1;
  char ch;
  _value = 0;
  while (!isdigit(ch = getchar())) {
    if (ch == -1) return false;
    ch == '-' ? _sign = -1 : _sign = 1;
  }
  do {
    _value = _value * 10 + (ch - '0');
  } while (isdigit(ch = getchar()));
  _value *= _sign;
  return true;
}
int N, Q, cnt = 1;
vector<int> values, positions, aib, checked;
void InsertAib(int pos, int val) {
  if (checked[pos] == cnt) return;
  checked[pos] = cnt;
  for (; pos <= N; pos += pos & (-pos)) {
    aib[pos] += val;
  }
}
int QueryAib(int pos) {
  int ans = 0;
  for (; pos; pos -= pos & (-pos)) {
    ans += aib[pos];
  }
  return ans;
}
void Verif(int val, int add) {
  if (val > 1 && positions[val - 1] > positions[val]) InsertAib(val - 1, add);
  if (val < N && positions[val] > positions[val + 1]) InsertAib(val, add);
}
int main() {
  int i;
  GetNr(N);
  values.resize(1 + N);
  positions.resize(1 + N);
  checked.resize(1 + N);
  aib.resize(1 + N);
  for (i = 1; i <= N; ++i) {
    GetNr(values[i]);
    positions[values[i]] = i;
  }
  for (i = 1; i <= N; ++i) {
    if (positions[i + 1] < positions[i]) {
      InsertAib(i, 1);
    }
  }
  int t, x, y;
  GetNr(Q);
  for (i = 0; i < Q; ++i) {
    GetNr(t);
    GetNr(x);
    GetNr(y);
    if (t == 1) {
      printf("%d\n", 1 + QueryAib(y - 1) - QueryAib(x - 1));
    } else {
      x = values[x];
      y = values[y];
      ++cnt;
      Verif(x, -1);
      Verif(y, -1);
      swap(values[positions[x]], values[positions[y]]);
      swap(positions[x], positions[y]);
      ++cnt;
      Verif(x, 1);
      Verif(y, 1);
    }
  }
  return 0;
}
