#include <bits/stdc++.h>
int father[200001];
int nxt[200001];
int getFather(int);
int getFather(int x) {
  if (father[x] == x) {
    return x;
  } else {
    father[x] = getFather(father[x]);
    return father[x];
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int n, q;
  std::cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    father[i] = i;
    nxt[i] = i + 1;
  }
  for (int i = 1; i <= q; i++) {
    int op;
    int x, y;
    std::cin >> op >> x >> y;
    if (op == 1) {
      father[getFather(x)] = getFather(y);
    } else if (op == 2) {
      x = x + 1;
      while (x <= y) {
        father[getFather(x - 1)] = getFather(x);
        int tmp = nxt[x];
        nxt[x] = nxt[y];
        x = tmp;
      }
    } else {
      if (getFather(x) == getFather(y)) {
        std::cout << "YES\n";
      } else {
        std::cout << "NO\n";
      }
    }
  }
  return 0;
}
