#include <bits/stdc++.h>
using namespace std;
const int MaxN = 5000005;
typedef int Tar[MaxN];
int n, loai, x, y, nques;
Tar a, b, val, l, h;
void Build(int x, int low, int high) {
  l[x] = low;
  h[x] = high;
  val[x] = 0;
  if (low != high) {
    int mid = (low + high) / 2;
    Build(2 * x, low, mid);
    Build(2 * x + 1, mid + 1, high);
  }
}
void Update(int i, int x, int value) {
  if (l[i] == h[i])
    val[i] = value;
  else {
    if (x <= h[2 * i])
      Update(i * 2, x, value);
    else
      Update(i * 2 + 1, x, value);
    val[i] = val[i * 2] + val[i * 2 + 1];
  }
}
int Get(int i, int low, int high) {
  if ((low <= l[i]) && (h[i] <= high))
    return val[i];
  else {
    int ans = 0;
    if (low <= h[2 * i]) ans += Get(i * 2, low, high);
    if (high > h[2 * i]) ans += Get(i * 2 + 1, low, high);
    return ans;
  }
}
void init() {
  Build(1, 1, n);
  for (int i = 1; i <= n - 1; i++)
    if (b[i] < b[i + 1]) {
      Update(1, i, 0);
    } else
      Update(1, i, 1);
}
void Swap(int x, int y) {
  int tmp;
  tmp = a[x];
  a[x] = a[y];
  a[y] = tmp;
  b[a[x]] = x;
  b[a[y]] = y;
  if (a[x] != 1) {
    if (b[a[x] - 1] < b[a[x]])
      Update(1, a[x] - 1, 0);
    else
      Update(1, a[x] - 1, 1);
  }
  if (a[x] != n) {
    if (b[a[x]] < b[a[x] + 1])
      Update(1, a[x], 0);
    else
      Update(1, a[x], 1);
  }
  if (a[y] != 1) {
    if (b[a[y] - 1] < b[a[y]])
      Update(1, a[y] - 1, 0);
    else
      Update(1, a[y] - 1, 1);
  }
  if (a[y] != n) {
    if (b[a[y]] < b[a[y] + 1])
      Update(1, a[y], 0);
    else
      Update(1, a[y], 1);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[a[i]] = i;
  }
  init();
  cin >> nques;
  for (int ques = 1; ques <= nques; ques++) {
    cin >> loai >> x >> y;
    if (loai == 2)
      Swap(x, y);
    else
      cout << Get(1, x, y - 1) + 1 << endl;
  }
  return 0;
}
