#include <bits/stdc++.h>
using namespace std;
struct tree {
  int sum;
  int pre, suff;
};
tree m[4 * 300100];
int n, q;
int a[300100], pos[300100];
void init(int node, int b, int e);
void update(int node, int b, int e, int k);
int query(int node, int b, int e, int x, int y);
int main() {
  int i, j, k, l, v, test, t = 1;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  init(1, 1, n);
  scanf("%d", &q);
  int type, r1, r2;
  for (int i1 = 1; i1 <= q; i1++) {
    scanf("%d %d %d", &type, &r1, &r2);
    if (type == 1) {
      int ans = 1, last = pos[r1];
      ans = query(1, 1, n, r1, r2);
      printf("%d\n", ans);
    } else {
      swap(a[r1], a[r2]);
      swap(pos[a[r1]], pos[a[r2]]);
      update(1, 1, n, a[r1]);
      update(1, 1, n, a[r2]);
      update(1, 1, n, a[r1]);
    }
  }
  return 0;
}
int query(int node, int b, int e, int x, int y) {
  if (b == e) {
    return m[node].sum;
  }
  int k = e - b + 1, l;
  if (b == x && e == y) {
    return m[node].sum;
  }
  int left, right, mid, ret = 0;
  left = node << 1;
  right = left + 1;
  mid = b + e;
  mid /= 2;
  if (y <= mid) {
    return query(left, b, mid, x, y);
  } else if (x > mid) {
    return query(right, mid + 1, e, x, y);
  } else {
    ret += query(left, b, mid, x, mid);
    ret += query(right, mid + 1, e, mid + 1, y);
  }
  if (pos[mid] < pos[mid + 1]) ret--;
  return ret;
}
void update(int node, int b, int e, int k) {
  if (b == e) {
    m[node].sum = 1;
    m[node].pre = pos[b];
    m[node].suff = pos[e];
    return;
  }
  int left, right, mid;
  left = node << 1;
  right = left + 1;
  mid = b + e;
  mid /= 2;
  if (k <= mid)
    update(left, b, mid, k);
  else
    update(right, mid + 1, e, k);
  m[node].pre = pos[b];
  m[node].suff = pos[e];
  m[node].sum = m[left].sum + m[right].sum;
  if (m[left].suff < m[right].pre) {
    m[node].sum--;
  }
}
void init(int node, int b, int e) {
  if (b == e) {
    m[node].sum = 1;
    m[node].pre = pos[b];
    m[node].suff = pos[e];
    return;
  }
  int left, right, mid;
  left = node << 1;
  right = left + 1;
  mid = b + e;
  mid /= 2;
  init(left, b, mid);
  init(right, mid + 1, e);
  m[node].pre = pos[b];
  m[node].suff = pos[e];
  m[node].sum = m[left].sum + m[right].sum;
  if (m[left].suff < m[right].pre) {
    m[node].sum--;
  }
}
