#include <bits/stdc++.h>
int inp[300005], pos[300005], tree[300005], n;
int read(int idx) {
  int ret = 0;
  while (idx >= 1) {
    ret += tree[idx];
    idx -= idx & -idx;
  }
  return ret;
}
void update(int idx, int val) {
  while (idx <= n) {
    tree[idx] += val;
    idx += idx & -idx;
  }
}
int main() {
  int i, qu, tp, x, y, a, b, val, r;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &inp[i]);
    pos[inp[i]] = i;
  }
  for (i = 2; i <= n; i++) {
    if (pos[i] < pos[i - 1]) update(i, 1);
  }
  scanf("%d", &qu);
  while (qu--) {
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d%d", &x, &y);
      printf("%d\n", read(y) - read(x) + 1);
    } else {
      scanf("%d%d", &x, &y);
      a = inp[x];
      b = inp[y];
      pos[b] = x;
      pos[a] = y;
      inp[y] = a;
      inp[x] = b;
      if (a + 1 <= n) {
        if (pos[a + 1] < pos[a])
          val = 1;
        else
          val = 0;
        r = read(a + 1) - read(a);
        update(a + 1, val - r);
      }
      if (a - 1 >= 1) {
        if (pos[a] < pos[a - 1])
          val = 1;
        else
          val = 0;
        r = read(a) - read(a - 1);
        update(a, val - r);
      }
      if (b + 1 <= n) {
        if (pos[b + 1] < pos[b])
          val = 1;
        else
          val = 0;
        r = read(b + 1) - read(b);
        update(b + 1, val - r);
      }
      if (b - 1 >= 1) {
        if (pos[b] < pos[b - 1])
          val = 1;
        else
          val = 0;
        r = read(b) - read(b - 1);
        update(b, val - r);
      }
    }
  }
  return 0;
}
