#include <bits/stdc++.h>
using namespace std;
int n, nques, st, fi, dem, x, y, loai, t;
int a[105], vt[105];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    vt[a[i]] = i;
  }
  cin >> nques;
  for (int ques = 1; ques <= nques; ques++) {
    cin >> loai >> x >> y;
    if (loai == 2) {
      t = a[x];
      a[x] = a[y];
      a[y] = t;
      vt[a[x]] = x;
      vt[a[y]] = y;
    } else {
      dem = 1;
      for (int i = x + 1; i <= y; i++)
        if (vt[i] < vt[i - 1]) dem++;
      cout << dem << endl;
    }
  }
}
