#include <bits/stdc++.h>
using namespace std;
int low[2000000], high[2000000], value[2000000], n, a[5000000], pos[5000000];
void build(int s, int dau, int cuoi) {
  low[s] = dau;
  high[s] = cuoi;
  value[s] = 0;
  if (dau != cuoi) {
    int mid = (dau + cuoi) / 2;
    build(s * 2, dau, mid);
    build(s * 2 + 1, mid + 1, cuoi);
  }
}
int getvalue(int dau, int cuoi, int s) {
  if ((dau <= low[s]) && (high[s] <= cuoi))
    return value[s];
  else {
    int ans = 0;
    if (dau <= high[s * 2]) ans += getvalue(dau, cuoi, s * 2);
    if (cuoi > high[s * 2]) ans += getvalue(dau, cuoi, s * 2 + 1);
    return ans;
  }
}
void push(int pivot, int gt, int s) {
  if (low[s] == high[s])
    value[s] = gt;
  else {
    if (pivot <= high[s * 2])
      push(pivot, gt, s * 2);
    else
      push(pivot, gt, s * 2 + 1);
    value[s] = value[s * 2] + value[s * 2 + 1];
  }
}
void init() {
  int i;
  for (i = 1; i <= n - 1; i++)
    if (pos[i] < pos[i + 1]) {
      push(i, 0, 1);
    } else
      push(i, 1, 1);
}
void change(int x, int y) {
  int temp;
  temp = a[x];
  a[x] = a[y];
  a[y] = temp;
  pos[a[x]] = x;
  pos[a[y]] = y;
  if (a[x] != 1) {
    if (pos[a[x] - 1] < pos[a[x]])
      push(a[x] - 1, 0, 1);
    else
      push(a[x] - 1, 1, 1);
  }
  if (a[x] != n) {
    if (pos[a[x]] < pos[a[x] + 1])
      push(a[x], 0, 1);
    else
      push(a[x], 1, 1);
  }
  if (a[y] != 1) {
    if (pos[a[y] - 1] < pos[a[y]])
      push(a[y] - 1, 0, 1);
    else
      push(a[y] - 1, 1, 1);
  }
  if (a[y] != n) {
    if (pos[a[y]] < pos[a[y] + 1])
      push(a[y], 0, 1);
    else
      push(a[y], 1, 1);
  }
}
int main() {
  cin >> n;
  int i, x, y;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    pos[x] = i;
    a[i] = x;
  }
  build(1, 1, n);
  init();
  int query, tp;
  cin >> query;
  for (i = 1; i <= query; i++) {
    scanf("%d%d%d", &tp, &x, &y);
    if (tp == 1)
      printf("%d\n", getvalue(x, y - 1, 1) + 1);
    else
      change(x, y);
  }
  return 0;
}
