#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 100100;
int a[maxn];
int pos[maxn];
int n, m;
int tree[maxn + 1];
int val[maxn];
int read(int idx) {
  int sum = 0;
  for (; idx > 0; idx -= idx & -idx) sum += tree[idx];
  return sum;
}
void update(int idx, int x) {
  int i = idx;
  for (; idx <= n; idx += idx & -idx) tree[idx] += x - val[i];
  val[i] = x;
}
int shave(int x, int y) { return 1 + read(y) - read(x); }
void check(int i) {
  if (i <= 1 || i > n) return;
  update(i, pos[i] < pos[i - 1]);
}
void swapit(int x, int y) {
  swap(a[x], a[y]);
  pos[a[x]] = x;
  pos[a[y]] = y;
  check(a[x]);
  check(a[x] + 1);
  check(a[y]);
  check(a[y] + 1);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = (0); i < (n); ++i) cin >> a[i], pos[a[i]] = i;
  for (int i = (1); i < (n + 1); ++i) check(i);
  cin >> m;
  for (int i = (0); i < (m); ++i) {
    int p, x, y;
    cin >> p >> x >> y;
    if (p == 1) {
      cout << shave(x, y) << "\n";
    } else {
      x--, y--;
      swapit(x, y);
    }
  }
}
