#include <bits/stdc++.h>
using namespace std;
int tree[(1 << 19)];
void add(int pos, int val) {
  for (int i = pos; i < (1 << 19); i = ((i) | (i + 1))) tree[i] += val;
}
int sum(int pos) {
  int ans = 0;
  for (int i = pos; i > 0; i = ((i) & (i - 1))) ans += tree[i - 1];
  return ans;
}
int N;
int p[300010], pinv[300010];
int d[300010];
void update_d(int pos, int val) {
  add(pos, val - d[pos]);
  d[pos] = val;
}
int shave_query(int L, int R) {
  int ans = 1;
  ans += sum(R - 1) - sum(L);
  return ans;
}
void update(int id) {
  if (id >= 0) update_d(id, ((pinv[id] > pinv[id + 1]) ? 1 : 0));
}
void swap_query(int x, int y) {
  int px = p[x], py = p[y];
  p[x] = py;
  p[y] = px;
  pinv[py] = x;
  pinv[px] = y;
  update(py - 1);
  update(py);
  update(px - 1);
  update(px);
}
int main(void) {
  int Q, i, t, x, y;
  cin >> N;
  for ((i) = 0; (i) < (int)(N); (i)++) {
    scanf("%d", &p[i]);
    p[i]--;
    pinv[p[i]] = i;
  }
  for ((i) = 0; (i) < (int)(N - 1); (i)++)
    if (pinv[i] > pinv[i + 1]) update_d(i, 1);
  cin >> Q;
  for ((i) = 0; (i) < (int)(Q); (i)++) {
    scanf("%d%d%d", &t, &x, &y);
    if (t == 1) {
      int ans = shave_query(x - 1, y);
      printf("%d\n", ans);
    } else {
      swap_query(x - 1, y - 1);
    }
  }
  return 0;
}
