#include <bits/stdc++.h>
using namespace std;
long long int num[300500];
long long int pos[300500];
long long int st[300500 * 4];
long long int n, N;
long long int recur(long long int v, long long int l, long long int r,
                    long long int left, long long int right) {
  if (right <= l || r <= left) return 0;
  if (left <= l && r <= right) return st[v];
  long long int mid = (l + r) >> 1;
  long long int ans = 0;
  ans += recur(v * 2 + 0, l, mid, left, right);
  ans += recur(v * 2 + 1, mid, r, left, right);
  return ans;
}
void change(long long int pos, long long int value) {
  pos += N;
  st[pos] = value;
  while (1 < pos) {
    pos /= 2;
    st[pos] = st[pos * 2 + 0] + st[pos * 2 + 1];
  }
}
int main() {
  cin >> n;
  for (N = 1; N <= n; N *= 2)
    ;
  for (long long int i = 0; i < ((long long int)(n + 1)); ++i)
    if (i) {
      cin >> num[i];
      pos[num[i]] = i;
    }
  for (long long int i = 0; i < ((long long int)(n)); ++i)
    if (i) {
      if (pos[i] < pos[i + 1])
        change(i, 0);
      else
        change(i, 1);
    }
  long long int q;
  cin >> q;
  for (long long int i = 0; i < ((long long int)(q)); ++i) {
    long long int type, x, y;
    cin >> type >> x >> y;
    if (type == 1) {
      cout << 1 + recur(1, 0, N, x, y) << endl;
    } else {
      long long int nx = num[x];
      long long int ny = num[y];
      swap(num[x], num[y]);
      swap(pos[nx], pos[ny]);
      for (long long int step = 0; step < ((long long int)(2)); ++step) {
        long long int t = step == 0 ? nx : ny;
        if (t != 1) change(t - 1, pos[t - 1] < pos[t] ? 0 : 1);
        if (t != n) change(t, pos[t] < pos[t + 1] ? 0 : 1);
      }
    }
  }
}
