#include <bits/stdc++.h>
using namespace std;
const int mn = 300 * 1000 + 5;
int a[mn];
int b[mn];
int bad[mn];
int t[4 * mn];
void construct(int v, int l, int r) {
  if (l == r)
    t[v] = bad[r];
  else {
    int mid = (l + r) / 2;
    construct(2 * v, l, mid);
    construct(2 * v + 1, mid + 1, r);
    t[v] = t[v * 2] + t[v * 2 + 1];
  }
}
int ans(int v, int l, int r, int x, int y) {
  if (x > y) return 0;
  if (x == l && y == r) return t[v];
  int mid = (l + r) / 2;
  return ans(v * 2, l, mid, x, min(y, mid)) +
         ans(v * 2 + 1, mid + 1, r, max(x, mid + 1), y);
}
void update(int v, int l, int r, int pos, int val) {
  if (l == r)
    t[v] = val;
  else {
    int mid = (l + r) / 2;
    if (pos <= mid)
      update(v * 2, l, mid, pos, val);
    else
      update(v * 2 + 1, mid + 1, r, pos, val);
    t[v] = t[v * 2] + t[v * 2 + 1];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[a[i]] = i;
  }
  for (int i = 2; i <= n; i++) {
    if (b[i] < b[i - 1]) bad[i] = 1;
  }
  construct(1, 1, n);
  int q;
  cin >> q;
  for (int k = 0; k < q; k++) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      cout << ans(1, 1, n, x + 1, y) + 1 << "\n";
    } else {
      int x1 = a[x], y1 = a[y];
      swap(a[x], a[y]);
      swap(b[x1], b[y1]);
      if (b[x1] < b[x1 + 1])
        update(1, 1, n, x1 + 1, 0);
      else
        update(1, 1, n, x1 + 1, 1);
      if (b[x1 - 1] < b[x1])
        update(1, 1, n, x1, 0);
      else
        update(1, 1, n, x1, 1);
      if (b[y1] < b[y1 + 1])
        update(1, 1, n, y1 + 1, 0);
      else
        update(1, 1, n, y1 + 1, 1);
      if (b[y1 - 1] < b[y1])
        update(1, 1, n, y1, 0);
      else
        update(1, 1, n, y1, 1);
    }
  }
  return 0;
}
