#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 3e5 + 10, mod = 1e9 + 7, M = 3e3 + 10;
const double PI = 3.1415926535;
int tr[N], a[N], va[N], pos[N], n;
void add(int pos, int value) {
  for (int i = pos; i <= n; i += (i & -i)) tr[i] += value;
}
int sum(int pos) {
  int res = 0;
  for (int i = pos; i; i -= (i & -i)) res += tr[i];
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    pos[a[i]] = i;
  }
  for (int i = 1; i < n; i++) {
    if (pos[i] > pos[i + 1]) {
      add(i, 1);
      va[i] = 1;
    } else
      va[i] = 0;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int k, x, y;
    scanf("%d %d%d", &k, &x, &y);
    if (k == 1)
      printf("%d\n", sum(y - 1) - sum(x - 1) + 1);
    else {
      swap(pos[a[x]], pos[a[y]]);
      swap(a[x], a[y]);
      {
        int c = a[x];
        if (a[x] - 1 > 0)
          if (pos[a[x] - 1] > pos[a[x]])
            add(a[x] - 1, 1 - va[a[x] - 1]), va[a[x] - 1] = 1;
          else
            add(a[x] - 1, -va[a[x] - 1]), va[a[x] - 1] = 0;
        if (a[x] + 1 <= n)
          if (pos[a[x]] > pos[a[x] + 1])
            add(a[x], 1 - va[a[x]]), va[a[x]] = 1;
          else
            add(a[x], -va[a[x]]), va[a[x]] = 0;
      }
      {
        int c = a[y];
        if (a[y] - 1 > 0)
          if (pos[a[y] - 1] > pos[a[y]])
            add(a[y] - 1, 1 - va[a[y] - 1]), va[a[y] - 1] = 1;
          else
            add(a[y] - 1, -va[a[y] - 1]), va[a[y] - 1] = 0;
        if (a[y] + 1 <= n)
          if (pos[a[y]] > pos[a[y] + 1])
            add(a[y], 1 - va[a[y]]), va[a[y]] = 1;
          else
            add(a[y], -va[a[y]]), va[a[y]] = 0;
      }
    }
  }
  return 0;
}
