#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, m, a[N], b[N];
struct item {
  int val, le, ri;
};
item t[4 * N];
inline item mrg(item a, item b) {
  if (a.le == -1) {
    return b;
  }
  if (b.le == -1) {
    return a;
  }
  item c;
  c.val = a.val + b.val - (a.ri < b.le);
  c.le = a.le;
  c.ri = b.ri;
  return c;
}
void build(int v, int l, int r) {
  if (l == r) {
    t[v].val = 1;
    t[v].le = t[v].ri = b[l];
    return;
  }
  int mid = (r + l) >> 1;
  build(v + v, l, mid);
  build(v + v + 1, mid + 1, r);
  t[v] = mrg(t[v + v], t[v + v + 1]);
}
void update(int v, int l, int r, int pos, int val) {
  if (l == r) {
    t[v].le = t[v].ri = val;
    return;
  }
  int mid = (r + l) >> 1;
  if (pos <= mid) {
    update(v + v, l, mid, pos, val);
  } else {
    update(v + v + 1, mid + 1, r, pos, val);
  }
  t[v] = mrg(t[v + v], t[v + v + 1]);
}
item bad = {-1, -1, -1};
item get(int v, int l, int r, int tl, int tr) {
  if (l > r || l > tr || tl > r) {
    return bad;
  }
  if (tl <= l && r <= tr) {
    return t[v];
  }
  int mid = (r + l) >> 1;
  return mrg(get(v + v, l, mid, tl, tr), get(v + v + 1, mid + 1, r, tl, tr));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[a[i]] = i;
  }
  build(1, 1, n);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int type, l, r;
    cin >> type >> l >> r;
    if (type == 1) {
      cout << get(1, 1, n, l, r).val << "\n";
    } else {
      update(1, 1, n, a[l], r);
      update(1, 1, n, a[r], l);
      swap(a[l], a[r]);
    }
  }
}
