#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, q;
struct DSU {
  int p[maxn + 1], rank[maxn + 1];
  void init() {
    for (int i = 1; i <= n; i++) {
      p[i] = i;
      rank[i] = 0;
    }
  }
  void join(int a, int b) {
    int A = pa(a), B = pa(b);
    if (A == B) return;
    if (rank[A] >= rank[B]) {
      p[B] = A;
      if (rank[A] == rank[B]) rank[A]++;
    } else
      p[A] = B;
  }
  int pa(int a) { return p[a] == a ? a : p[a] = pa(p[a]); }
} S;
set<int> s;
int main() {
  scanf("%d%d", &n, &q);
  int t, l, r;
  for (int i = 1; i <= n; i++) s.insert(i);
  S.init();
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d", &t, &l, &r);
    if (t == 3) {
      if (S.pa(l) == S.pa(r)) {
        puts("YES");
      } else
        puts("NO");
    } else if (t == 1) {
      S.join(l, r);
    } else {
      if (s.size() <= 1) continue;
      int pr;
      auto st = s.lower_bound(l);
      auto fi = --s.upper_bound(r);
      if ((*st) >= (*fi)) continue;
      for (auto it = st;;) {
        if (it == st) {
          pr = *it;
          it++;
          continue;
        }
        S.join(pr, *it);
        if (it != fi)
          s.erase(it++);
        else
          break;
      }
    }
  }
  return 0;
}
