#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 10, INF = 1e9;
int fn[MAXN], a[MAXN], b[MAXN], n;
set<pair<int, int> > s;
void upd(int p, int val) {
  for (++p; p < MAXN; p += p & (-p)) fn[p] += val;
}
int get(int p) {
  int ans = 0;
  for (; p > 0; p -= p & (-p)) ans += fn[p];
  return ans;
}
void calc(int index, int val) {
  b[index] = val;
  auto itr = s.upper_bound({index, INF});
  itr--;
  int l = itr->first, r = itr->second;
  if (index - l > 0 and b[index] <= b[index - 1]) {
    s.erase({l, r});
    s.insert({l, index - 1});
    s.insert({index, r});
    l = index;
    upd(index, 1);
  }
  if (r - index > 0 and b[index] >= b[index + 1]) {
    s.erase({l, r});
    s.insert({l, index});
    s.insert({index + 1, r});
    r = index;
    upd(index + 1, 1);
  }
  if (index == l and index > 0 and b[index] > b[index - 1]) {
    auto itr2 = s.lower_bound({index, -1});
    itr2--;
    s.erase({l, r});
    l = itr2->first;
    s.erase(itr2);
    s.insert({l, r});
    upd(index, -1);
  }
  if (index == r and index < n - 1 and b[index] < b[index + 1]) {
    auto itr2 = s.upper_bound({r, INF});
    s.erase({l, r});
    r = itr2->second;
    s.erase(itr2);
    s.insert({l, r});
    upd(index + 1, -1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
    b[a[i]] = i;
  }
  int ptr = 0;
  for (int j = 0; j < n; j++) {
    if (j > 0) {
      if (b[j] < b[j - 1]) {
        s.insert({ptr, j - 1});
        upd(ptr, 1);
        ptr = j;
      }
    }
  }
  s.insert({ptr, n - 1});
  upd(ptr, 1);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r;
      cin >> l >> r;
      cout << get(r) - get(l) + 1 << '\n';
    } else {
      int x1, x2, ind1, ind2;
      cin >> x1 >> x2;
      x1--;
      x2--;
      ind1 = a[x1];
      ind2 = a[x2];
      swap(a[x1], a[x2]);
      calc(ind1, x2);
      calc(ind2, x1);
    }
  }
  return 0;
}
