#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const long long INF = 1e9 + 19;
int n, q;
int p[N];
int rev[N];
int tree[N];
void add(int pos, int val) {
  for (; pos <= n; pos |= (pos + 1)) tree[pos + 1] += val;
}
int get(int r) {
  int sum = 0;
  for (; r > 0; r &= (r - 1)) sum += tree[r];
  return sum;
}
int get(int l, int r) { return get(r) - get(l); }
void f(int val, int cof) {
  if (0 <= val && val + 1 < n && rev[val] > rev[val + 1]) add(val, cof);
}
void read() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
  }
  for (int i = 0; i < n; i++) rev[p[i]] = i;
  for (int i = 0; i < n; i++) f(i, 1);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int type, x, y;
    scanf("%d%d%d", &type, &x, &y);
    x--;
    y--;
    if (type == 1) {
      printf("%d\n", get(x, y) + 1);
    } else {
      assert(type == 2);
      vector<int> tmp = {p[x], p[x] - 1, p[y], p[y] - 1};
      sort((tmp).begin(), (tmp).end());
      tmp.resize(unique((tmp).begin(), (tmp).end()) - tmp.begin());
      for (auto w : tmp) f(w, -1);
      swap(p[x], p[y]);
      swap(rev[p[x]], rev[p[y]]);
      for (auto w : tmp) f(w, 1);
    }
  }
}
void solve() {}
void stress() {}
int main() {
  if (1) {
    read();
    solve();
  } else {
    stress();
  }
  return 0;
}
