#include <bits/stdc++.h>
using namespace std;
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
  if (rsz <= 0) {
    ptr = 0;
    rsz = fread(bf, 1, bfsz, stdin);
    if (rsz <= 0) return EOF;
  }
  --rsz;
  return bf[ptr++];
}
void ga(char &c) {
  c = EOF;
  while (!isalpha(c)) c = gc();
}
int gs(char s[]) {
  int l = 0;
  char c = gc();
  while (isspace(c)) c = gc();
  while (c != EOF && !isspace(c)) {
    s[l++] = c;
    c = gc();
  }
  s[l] = '\0';
  return l;
}
template <class T>
bool gi(T &v) {
  v = 0;
  char c = gc();
  while (c != EOF && c != '-' && !isdigit(c)) c = gc();
  if (c == EOF) return false;
  bool neg = c == '-';
  if (neg) c = gc();
  while (isdigit(c)) {
    v = v * 10 + c - '0';
    c = gc();
  }
  if (neg) v = -v;
  return true;
}
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
int toInt(char xx) { return xx - '0'; }
char toChar(int xx) { return xx + '0'; }
int isDigit(char xx) { return ('0' <= xx && xx <= '9'); }
void swapInt(int &x, int &y) {
  x = x ^ y;
  y = x ^ y;
  x = x ^ y;
}
class bigint {
 public:
  int a[100];
  void add(bigint &y);
  void print();
};
void bigint::add(bigint &y) {
  int i, d;
  if (a[0] < y.a[0]) a[0] = y.a[0];
  d = 0;
  for (i = 1; i <= a[0]; i++) {
    a[i] += y.a[i] + d;
    d = a[i] / 1000000;
    a[i] %= 1000000;
  }
  while (d > 0) {
    a[0]++;
    a[a[0]] = d % 1000000;
    d /= 1000000;
  }
}
void bigint::print() {
  int i, n = a[0];
  cout << a[n];
  for (i = n - 1; i >= 1; i--) {
    if (a[i] < 10)
      cout << "00000";
    else if (a[i] < 100)
      cout << "0000";
    else if (a[i] < 1000)
      cout << "000";
    else if (a[i] < 10000)
      cout << "00";
    else if (a[i] < 100000)
      cout << "0";
    cout << a[i];
  }
}
int exitInput = 0;
int ntest = 1, itest = 1;
void read();
void solve();
int main() {
  clock_t t1, t2;
  t1 = clock();
  for (itest = 1; itest <= ntest; ++itest) {
    read();
    if (exitInput) {
      break;
    }
    if (itest > 1) {
    }
    solve();
  }
  t2 = clock();
  return 0;
}
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const long long Mod = 1e9 + 7;
const int maxn = 3 * 1e5 + 2;
int n, a[maxn], idx[maxn], b[maxn], updated[maxn];
int it[4 * maxn + 4];
void build_it(int node, int l, int r) {
  if (l == r) {
    it[node] = b[r];
    return;
  }
  build_it((node << 1), l, ((l + r) >> 1));
  build_it(((node << 1) + 1), ((l + r) >> 1) + 1, r);
  it[node] = it[(node << 1)] + it[((node << 1) + 1)];
}
int query(int node, int l, int r, int i, int j) {
  if (r < i || j < l) {
    return 0;
  }
  if (i <= l && r <= j) {
    return it[node];
  }
  int p1 = query((node << 1), l, ((l + r) >> 1), i, j);
  int p2 = query(((node << 1) + 1), ((l + r) >> 1) + 1, r, i, j);
  return p1 + p2;
}
void update(int node, int l, int r, int x) {
  if (r < x || x < l) {
    return;
  }
  if (l == r && x == r) {
    it[node] ^= 1;
    return;
  }
  update((node << 1), l, ((l + r) >> 1), x);
  update(((node << 1) + 1), ((l + r) >> 1) + 1, r, x);
  it[node] = it[(node << 1)] + it[((node << 1) + 1)];
}
void read() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    idx[a[i]] = i;
  }
  for (int i = 1; i <= n - 1; ++i) {
    if (idx[i] > idx[i + 1]) {
      b[i] = 1;
    } else {
      b[i] = 0;
    }
  }
}
void updateMe(int val, int cur_idx, int new_idx) {
  int k;
  if ((cur_idx >= idx[val - 1] && new_idx <= idx[val - 1]) ||
      (cur_idx <= idx[val - 1] && new_idx >= idx[val - 1])) {
    if (!updated[val - 1]) {
      update(1, 1, n, val - 1);
      updated[val - 1] = 1;
    }
  }
  if ((cur_idx >= idx[val + 1] && new_idx <= idx[val + 1]) ||
      (cur_idx <= idx[val + 1] && new_idx >= idx[val + 1])) {
    if (!updated[val]) {
      update(1, 1, n, val);
      updated[val] = 1;
    }
  }
}
void solve() {
  build_it(1, 1, n);
  int Q, id, x, y, res, val, cur_idx, new_idx;
  cin >> Q;
  while (Q--) {
    cin >> id >> x >> y;
    if (id == 2) {
      idx[a[x]] = y;
      idx[a[y]] = x;
      val = a[x];
      cur_idx = x;
      new_idx = y;
      updateMe(val, cur_idx, new_idx);
      val = a[y];
      cur_idx = y;
      new_idx = x;
      updateMe(val, cur_idx, new_idx);
      swap(a[x], a[y]);
      val = a[x];
      updated[val] = updated[val - 1] = 0;
      val = a[y];
      updated[val] = updated[val - 1] = 0;
    } else if (id == 1) {
      res = query(1, 1, n, x, y - 1);
      cout << res + 1 << endl;
    }
  }
}
