#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 10;
int p[mx], sz[mx];
int gp(int u) {
  while (u != p[u]) u = p[u];
  return u;
}
bool join(int u, int v) {
  int pu = gp(u), pv = gp(v);
  if (pu == pv) return false;
  if (sz[pu] < sz[pv]) swap(pu, pv);
  p[pv] = pu;
  sz[pu] += sz[pv];
  return true;
}
struct ival {
  int l, r;
  ival(int l, int r) : l(l), r(r) {}
  bool operator<(ival a) const { return r < a.l; }
};
set<ival> s;
set<ival>::iterator it1, it2;
int main() {
  int n, q, op, x, y;
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; i++) p[i] = i, sz[i] = 1;
  for (int i = 0; i < n; i++) {
    s.insert(ival(i, i));
  }
  while (q--) {
    scanf("%d %d %d", &op, &x, &y);
    x--, y--;
    if (op == 1) {
      join(x, y);
    } else if (op == 2) {
      ival qry(x, y);
      it1 = s.lower_bound(qry);
      int l = x, r = y;
      int bef = -1;
      while (it1 != s.end()) {
        it2 = it1;
        it2++;
        if (y < it1->l) break;
        if (bef != -1) {
          join(bef, it1->l);
        }
        bef = it1->l;
        l = min(l, it1->l);
        r = max(r, it1->r);
        s.erase(it1);
        it1 = it2;
      }
      s.insert(ival(l, r));
    } else if (op == 3) {
      if (gp(x) == gp(y))
        puts("YES");
      else {
        puts("NO");
      }
    }
  }
  return 0;
}
