#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 300228;
long long t[N * 4], i, j, n, m, a[N], p[N], o, b, l, r;
void modi(long long v, long long l, long long r, long long p, long long g) {
  if (p < l || p > r) return;
  if (l == r) {
    t[v] = g;
    return;
  }
  long long mid = (l + r) / 2;
  if (p <= mid)
    modi(v * 2, l, mid, p, g);
  else
    modi(v * 2 + 1, mid + 1, r, p, g);
  t[v] = t[v * 2] + t[v * 2 + 1];
}
long long get(long long v, long long l, long long r, long long _l,
              long long _r) {
  if (_l > _r) return 0;
  if (l == _l && r == _r) return t[v];
  long long mid = (l + r) / 2;
  return get(v * 2, l, mid, _l, min(_r, mid)) +
         get(v * 2 + 1, mid + 1, r, max(mid + 1, _l), _r);
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), p[a[i]] = i;
  for (i = 1; i < n; i++)
    if (p[i] > p[i + 1]) modi(1, 1, n, i + 1, 1);
  cin >> m;
  while (m--) {
    scanf("%d%d%d", &b, &l, &r);
    if (b == 1)
      printf("%d\n", get(1, 1, n, l + 1, r) + 1);
    else {
      swap(p[a[l]], p[a[r]]), swap(a[l], a[r]);
      if (p[a[l]] > p[a[l] + 1])
        modi(1, 1, n, a[l] + 1, 1);
      else
        modi(1, 1, n, a[l] + 1, 0);
      if (p[a[r]] > p[a[r] + 1])
        modi(1, 1, n, a[r] + 1, 1);
      else
        modi(1, 1, n, a[r] + 1, 0);
      if (p[a[l] - 1] > p[a[l]])
        modi(1, 1, n, a[l], 1);
      else
        modi(1, 1, n, a[l], 0);
      if (p[a[r] - 1] > p[a[r]])
        modi(1, 1, n, a[r], 1);
      else
        modi(1, 1, n, a[r], 0);
    }
  }
}
