#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int fa[N], link[N];
int n, q, op, x, y;
int Find(int f[], int x) { return f[x] == x ? x : f[x] = Find(f, f[x]); }
void Union(int f[], int x, int y) {
  int fx = Find(f, x), fy = Find(f, y);
  if (fx == fy)
    return;
  else if (fx > fy)
    f[fy] = fx;
  else
    f[fx] = fy;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) fa[i] = i, link[i] = i;
  while (q--) {
    scanf("%d%d%d", &op, &x, &y);
    if (op == 1)
      Union(fa, x, y);
    else if (op == 2) {
      int p = Find(link, x);
      for (int i = p; i <= y; i = Find(link, p) + 1) {
        Union(fa, Find(fa, p), Find(fa, i));
        Union(link, p, i);
      }
    } else
      puts(Find(fa, x) == Find(fa, y) ? "YES" : "NO");
  }
  return 0;
}
