#include <bits/stdc++.h>
using namespace std;
const int MaxN = 400005;
const long long oo = 1000000000000000000ll;
const long long Base = 1000000007;
typedef int Tarr[MaxN];
Tarr a, b, Val, c;
int n, m;
void Update(int i, int w) {
  c[i] += w;
  while (i <= n) {
    Val[i] += w;
    i += i & (-i);
  }
}
int Request(int i) {
  int Res = 0;
  while (i > 0) {
    Res += Val[i];
    i -= i & (-i);
  }
  return Res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) b[a[i]] = i;
  cin >> m;
  memset(Val, 0, sizeof(Val));
  b[0] = n + 1;
  for (int i = 1; i <= n; i++)
    if (b[i] < b[i - 1]) {
      Update(i, 1);
    }
  for (int i = 1; i <= m; i++) {
    int q, x, y;
    cin >> q >> x >> y;
    if (q == 1) {
      int r = Request(y) - Request(x) + 1;
      cout << r << endl;
    } else {
      swap(a[x], a[y]);
      x = a[x];
      y = a[y];
      swap(b[x], b[y]);
      if (b[x] < b[x - 1] && c[x] == 0) Update(x, 1);
      if (b[x] > b[x - 1] && c[x] == 1) Update(x, -1);
      if (b[y] < b[y - 1] && c[y] == 0) Update(y, 1);
      if (b[y] > b[y - 1] && c[y] == 1) Update(y, -1);
      if (b[x + 1] < b[x] && c[x + 1] == 0) Update(x + 1, 1);
      if (b[x + 1] > b[x] && c[x + 1] == 1) Update(x + 1, -1);
      if (b[y + 1] < b[y] && c[y + 1] == 0) Update(y + 1, 1);
      if (b[y + 1] > b[y] && c[y + 1] == 1) Update(y + 1, -1);
    }
  }
  return 0;
}
