#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 228228;
long long i, j, n, m, a[N], p[N], o, b, l, r;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), p[a[i]] = i;
  cin >> m;
  while (m--) {
    scanf("%d%d%d", &b, &l, &r);
    if (b == 1) {
      o = 1;
      for (i = l; i < r; i++)
        if (p[i] > p[i + 1]) o++;
      cout << o << "\n";
    } else
      swap(p[a[l]], p[a[r]]), swap(a[l], a[r]);
  }
}
