#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * (int)1e5 + 100;
const int BN = 30;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-8;
const double PI = acos(-1);
int trees[maxn];
int num[maxn];
int pos[maxn];
bool mark[maxn];
int n;
int lowbit(int x) { return x & (-x); }
void add(int pos, int num) {
  while (pos <= n) {
    trees[pos] += num;
    pos += lowbit(pos);
  }
}
int getsum(int end) {
  int sum = 0;
  while (end > 0) {
    sum += trees[end];
    end -= lowbit(end);
  }
  return sum;
}
int query(int l, int r) { return getsum(r) - getsum(l) + 1; }
void updates(int x) {
  if (mark[x] && pos[x] > pos[x - 1]) {
    add(x, -1);
    mark[x] = 0;
  }
  if (!mark[x] && pos[x] < pos[x - 1]) {
    add(x, 1);
    mark[x] = 1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    pos[num[i]] = i;
  }
  for (int i = 2; i <= n; i++)
    if (pos[i] < pos[i - 1]) mark[i] = 1;
  for (int i = 2; i <= n; i++)
    if (mark[i]) add(i, 1);
  int q;
  scanf("%d", &q);
  while (q--) {
    int op, x, y;
    scanf("%d%d%d", &op, &x, &y);
    if (op == 1)
      printf("%d\n", query(x, y));
    else {
      swap(num[x], num[y]);
      swap(pos[num[x]], pos[num[y]]);
      int t1 = num[x], t2 = num[y];
      updates(t1), updates(t2);
      if (t1 < n) updates(t1 + 1);
      if (t2 < n) updates(t2 + 1);
    }
  }
}
