#include <bits/stdc++.h>
using namespace std;
int pre[2000010];
int acca[200010];
int n, q;
void init() {
  for (int i = 0; i <= n; i++) {
    pre[i] = i;
    acca[i] = i + 1;
  }
}
int Find(int x) {
  if (pre[x] != x) pre[x] = Find(pre[x]);
  return pre[x];
}
void merge(int a, int b) {
  int x = Find(a);
  int y = Find(b);
  if (x != y) {
    pre[y] = x;
  }
}
int main() {
  scanf("%d%d", &n, &q);
  init();
  for (int i = 0; i < q; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if (a == 1) {
      merge(b, c);
    } else if (a == 2) {
      int temp;
      for (int j = b + 1; j <= c; j = temp) {
        merge(j - 1, j);
        temp = acca[j];
        acca[j] = c + 1;
      }
    } else if (a == 3) {
      b = Find(b);
      c = Find(c);
      if (b == c)
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
