#include <bits/stdc++.h>
using namespace std;
int n, a[300005], b[300005], an = 0, t;
int tree[300005], vis[5][300005];
void setIO(string a) {
  string in = a + ".in", out = a + ".out";
  freopen(in.c_str(), "r", stdin);
  freopen(out.c_str(), "w", stdout);
}
void add(int x, int delta) {
  for (int p = x; p <= n; p += p & (-p)) tree[p] += delta;
}
int ask(int x) {
  int an = 0;
  for (int p = x; p; p -= p & (-p)) an += tree[p];
  return an;
}
void mod(int x, int y, int z) {
  if (vis[z][x] == t) return;
  add(x, y);
  vis[z][x] = t;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &a[i]);
    b[a[i]] = i;
  }
  for (int i = (1); i <= (n); i++)
    if (b[i] < b[i - 1]) add(i, 1);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int opt, l, r;
    scanf("%d%d%d", &opt, &l, &r);
    if (opt == 1) {
      if (l > r) swap(l, r);
      printf("%d\n", ask(r) - ask(l) + 1);
    } else {
      ++t;
      int x = a[l], y = a[r];
      if (b[x] < b[x - 1]) mod(x, -1, 0);
      if (b[x + 1] < b[x]) mod(x + 1, -1, 0);
      if (b[y] < b[y - 1]) mod(y, -1, 0);
      if (b[y + 1] < b[y]) mod(y + 1, -1, 0);
      swap(a[l], a[r]);
      swap(b[x], b[y]);
      if (b[x] < b[x - 1]) mod(x, 1, 1);
      if (b[x + 1] < b[x]) mod(x + 1, 1, 1);
      if (b[y] < b[y - 1]) mod(y, 1, 1);
      if (b[y + 1] < b[y]) mod(y + 1, 1, 1);
    }
  }
  return 0;
}
