#include <bits/stdc++.h>
using namespace std;
int arr[300001];
int where[300001];
int tree[300005];
int n;
bool isBad(int val) {
  if (val == 1) return false;
  if (where[val - 1] > where[val])
    return true;
  else
    return false;
}
void add(int idx, int v) {
  while (idx <= n) {
    tree[idx] += v;
    idx += (idx & (-idx));
  }
}
int ask(int idx) {
  int ans = 0;
  while (idx > 0) {
    ans += tree[idx];
    idx -= (idx & (-idx));
  }
  return ans;
}
int query(int a, int b) {
  if (a == 1)
    return ask(b);
  else
    return ask(b) - ask(a - 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    where[arr[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (isBad(i)) {
      add(i, 1);
    }
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    int type;
    int x, y;
    scanf("%d %d %d", &type, &x, &y);
    if (type == 1) {
      int ans = 1;
      ans += query(x, y);
      if (isBad(x)) {
        ans--;
      }
      printf("%d\n", ans);
    } else {
      vector<int> vvalu;
      vvalu.push_back(arr[x]);
      vvalu.push_back(arr[y]);
      if (arr[x] != n) vvalu.push_back(arr[x] + 1);
      if (arr[y] != n) vvalu.push_back(arr[y] + 1);
      while (1) {
        sort(vvalu.begin(), vvalu.end());
        bool ch = false;
        for (int i = 1; i < vvalu.size(); i++) {
          if (vvalu[i] == vvalu[i - 1]) {
            swap(vvalu[i], vvalu[vvalu.size() - 1]);
            vvalu.pop_back();
            ch = true;
            break;
          }
        }
        if (!ch) break;
      }
      int v1 = arr[x];
      int v2 = arr[y];
      for (int p = 0; p < vvalu.size(); p++) {
        if (isBad(vvalu[p])) {
          add(vvalu[p], -1);
        }
      }
      swap(arr[x], arr[y]);
      swap(where[v1], where[v2]);
      for (int p = 0; p < vvalu.size(); p++) {
        if (isBad(vvalu[p])) {
          add(vvalu[p], 1);
        }
      }
    }
  }
  return 0;
}
