#include <bits/stdc++.h>
using namespace std;
int n, q;
int a[210000], x, y, z;
int b[210000];
int find(int x) {
  if (x == a[x])
    return a[x];
  else
    return a[x] = find(a[x]);
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) a[i] = i, b[i] = i - 1;
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d", &x, &y, &z);
    if (x == 1) {
      a[find(y)] = a[find(z)];
    } else if (x == 2) {
      for (int j = z, t = 0; j >= y; j = t) {
        t = b[j];
        b[j] = b[y];
        a[find(j)] = a[find(y)];
      }
    } else {
      if (find(y) == find(z))
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
