#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
struct que {
  int a, l, r;
} q[N];
int a[N], whe[N];
int ans[N];
int dp[N], n;
void solve(int l, int r) {
  if (l == r) {
    if (q[l].a == 1)
      ans[l] = dp[q[l].r] - dp[q[l].l] + 1;
    else {
      swap(whe[a[q[l].l]], whe[a[q[l].r]]);
      swap(a[q[l].l], a[q[l].r]);
    }
    return;
  }
  int mid = (l + r) >> 1;
  solve(l, mid);
  dp[1] = 1;
  for (int i = 2; i <= n; ++i)
    if (whe[i - 1] < whe[i])
      dp[i] = dp[i - 1];
    else
      dp[i] = dp[i - 1] + 1;
  if (mid + 1 <= r) solve(mid + 1, r);
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    whe[a[i]] = i;
  }
  dp[1] = 1;
  for (i = 2; i <= n; ++i)
    if (whe[i - 1] < whe[i])
      dp[i] = dp[i - 1];
    else
      dp[i] = dp[i - 1] + 1;
  int Q;
  scanf("%d", &Q);
  for (i = 1; i <= Q; ++i) scanf("%d%d%d", &q[i].a, &q[i].l, &q[i].r);
  solve(1, Q);
  for (i = 1; i <= Q; ++i)
    if (q[i].a == 1) printf("%d\n", ans[i]);
  return 0;
}
