#include <bits/stdc++.h>
using namespace std;
struct BIT {
  int dat[300010];
  void ins(int x, int v) {
    for (int i = x; i < 300010; i += i & -i) dat[i] += v;
  }
  int ask(int x) {
    int s = 0;
    for (int i = x; i; i -= i & -i) s += dat[i];
    return s;
  }
} bit;
int n, m, a[300010], p[300010];
set<pair<int, int> > s;
void s_ins(int l, int r) {
  bit.ins(l, +1);
  s.insert(pair<int, int>(l, r));
}
void s_del(set<pair<int, int> >::const_iterator it) {
  bit.ins(it->first, -1);
  s.erase(it);
}
void del(int x) {
  auto it = s.upper_bound(pair<int, int>(x, 300010));
  it--;
  int l = it->first;
  int r = it->second;
  s_del(it);
  if (l <= x - 1) s_ins(l, x - 1);
  s_ins(x, x);
  if (x + 1 <= r) s_ins(x + 1, r);
}
void ins(int x) {
  {
    auto it = s.upper_bound(pair<int, int>(x, 300010));
    it--;
    if (it != s.begin()) {
      auto jt = it;
      jt--;
      if (p[jt->second] < p[it->first]) {
        int l = jt->first;
        int r = it->second;
        s_del(it);
        s_del(jt);
        s_ins(l, r);
      }
    }
  }
  {
    auto it = s.upper_bound(pair<int, int>(x, 300010));
    if (it != s.end()) {
      auto jt = it;
      jt--;
      if (p[jt->second] < p[it->first]) {
        int l = jt->first;
        int r = it->second;
        s_del(it);
        s_del(jt);
        s_ins(l, r);
      }
    }
  }
}
int get_left(int x) {
  auto it = s.upper_bound(pair<int, int>(x, 300010));
  it--;
  return it->first;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) p[a[i]] = i;
  for (int i = 1, j; i <= n; i = j) {
    for (j = i + 1; j <= n && p[j] >= p[j - 1]; j++)
      ;
    s_ins(i, j - 1);
  }
  scanf("%d", &m);
  while (m--) {
    int op, x, y;
    scanf("%d%d%d", &op, &x, &y);
    if (op == 1) {
      int l = get_left(x);
      int r = get_left(y);
      printf("%d\n", bit.ask(r) - bit.ask(l - 1));
    } else {
      del(a[x]);
      del(a[y]);
      swap(a[x], a[y]);
      swap(p[a[x]], p[a[y]]);
      ins(a[x]);
      ins(a[y]);
    }
  }
  return 0;
}
