#include <bits/stdc++.h>
void p(int a);
void mer(int a, int b);
int find(int a);
int pre[200010] = {0}, an[200010] = {0};
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  p(n);
  while (q--) {
    int num, x, y, i, z;
    scanf("%d", &num);
    if (num == 1) {
      scanf("%d%d", &x, &y);
      if (x == y) continue;
      if (pre[x] != pre[y]) mer(x, y);
    } else if (num == 2) {
      scanf("%d%d", &x, &y);
      if (x == y) continue;
      if (y < x) {
        z = x;
        x = y;
        y = z;
      }
      for (i = x; i < y; i = z) {
        if (pre[i] != pre[i + 1]) mer(i, i + 1);
        z = an[i];
        an[i] = y;
      }
    } else if (num == 3) {
      scanf("%d%d", &x, &y);
      if (x == y)
        printf("YES\n");
      else {
        if (find(x) != find(y))
          printf("NO\n");
        else
          printf("YES\n");
      }
    }
  }
  return 0;
}
void p(int a) {
  int i;
  for (i = 1; i <= a; i++) {
    pre[i] = i;
    an[i] = i + 1;
  }
}
void mer(int a, int b) {
  int fa, fb;
  fa = find(a);
  fb = find(b);
  if (fa != fb) pre[fb] = fa;
}
int find(int a) {
  int r;
  r = a;
  while (r != pre[r]) r = pre[r];
  while (a != pre[a]) {
    int z;
    z = a;
    a = pre[a];
    pre[z] = r;
  }
  return r;
}
