#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC optimize("O4")
#pragma GCC optimize("O5")
#pragma GCC optimize("O6")
#pragma GCC optimize("O7")
#pragma GCC optimize("O8")
#pragma GCC optimize("Ofast")
const int maxn = 2e5 + 10;
int n, q;
int a[maxn], siz[maxn], par[maxn];
int L[maxn], R[maxn];
int get_par(int v) {
  if (par[v] == v) return v;
  return (par[v] = get_par(par[v]));
}
void dsu(int u, int v) {
  u = get_par(u);
  v = get_par(v);
  if (u == v) return;
  if (siz[u] > siz[v]) swap(u, v);
  if (siz[v] == siz[u]) ++siz[v];
  par[u] = v;
}
int main() {
  scanf("%d%d", &n, &q);
  set<int> se;
  for (int i = 1; i <= n; ++i) {
    par[i] = i;
    L[i] = i - 1;
    R[i] = i + 1;
    se.insert(i);
  }
  while (q--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int u, v;
      scanf("%d%d", &u, &v);
      dsu(u, v);
    }
    if (type == 2) {
      int l, r;
      scanf("%d%d", &l, &r);
      --r;
      auto it = se.lower_bound(l);
      l = *(it);
      for (int i = l; i <= r; i = R[i]) {
        dsu(l, i + 1);
        se.erase(i);
        R[L[i]] = R[i];
        L[R[i]] = L[i];
      }
    }
    if (type == 3) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (get_par(u) == get_par(v))
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
}
