#include <bits/stdc++.h>
using namespace std;
const int N = 4 * 10000;
int a[N], p[N];
int n;
struct node {
  int l, r;
  int w;
} t[N * 4];
void init(int l, int r, int rt) {
  t[rt].l = l;
  t[rt].r = r;
  int mid = (l + r) / 2;
  if (l == r) {
    if (p[l] < p[l + 1])
      t[rt].w = 0;
    else
      t[rt].w = 1;
    return;
  }
  init(l, mid, rt * 2);
  init(mid + 1, r, rt * 2 + 1);
  t[rt].w = t[rt * 2].w + t[rt * 2 + 1].w;
}
int query(int l, int r, int rt) {
  if (t[rt].l == l && t[rt].r == r) {
    return t[rt].w;
  }
  int mid = (t[rt].r + t[rt].l) / 2;
  if (r <= mid) {
    return query(l, r, rt * 2);
  } else if (l > mid) {
    return query(l, r, rt * 2 + 1);
  } else {
    return query(l, mid, rt * 2) + query(mid + 1, r, rt * 2 + 1);
  }
}
void update(int l, int v, int rt) {
  if (t[rt].r == t[rt].l) {
    t[rt].w += v;
    return;
  }
  t[rt].w += v;
  int mid = (t[rt].l + t[rt].r) / 2;
  if (l <= mid)
    update(l, v, rt * 2);
  else
    update(l, v, rt * 2 + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    p[a[i]] = i;
  }
  p[0] = 0;
  p[n + 1] = n;
  init(1, n, 1);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int type, l, r;
    scanf("%d%d%d", &type, &l, &r);
    if (type == 1) {
      printf("%d\n", query(l, r - 1, 1) + 1);
    } else {
      if (a[l] > a[r]) swap(l, r);
      int x[4], y[4];
      x[0] = a[l] - 1;
      x[1] = a[l];
      x[2] = a[r] - 1;
      x[3] = a[r];
      for (int i = 0; i < 4; i++) {
        if (p[x[i]] < p[x[i] + 1])
          y[i] = 0;
        else
          y[i] = 1;
      }
      swap(p[a[l]], p[a[r]]);
      swap(a[l], a[r]);
      for (int i = 0; i < 4; i++) {
        if (p[x[i]] < p[x[i] + 1])
          y[i] = -y[i];
        else
          y[i] = 1 - y[i];
        if (i == 2 && x[i] == x[i - 1]) continue;
        if (y[i] == 0) continue;
        update(x[i], y[i], 1);
      }
    }
  }
  for (int i = 1; i <= n; i++)
    ;
  return 0;
}
