#include <bits/stdc++.h>
struct oficinas {
  int valor;
  int sig;
};
int v[200002], vaux[200002];
int buscar(int buscado);
int main() {
  int n, q, type, x, y, i, A, B, aux;
  scanf("%d %d", &n, &q);
  for (i = 1; i <= n; i++) {
    v[i] = i;
    vaux[i] = i + 1;
  }
  for (i = 0; i < q; i++) {
    scanf("%d %d %d", &type, &x, &y);
    switch (type) {
      case 1:
        v[buscar(x)] = buscar(y);
        break;
      case 2:
        while (x < y) {
          v[buscar(x)] = buscar(y);
          aux = vaux[x];
          vaux[x] = vaux[y];
          x = aux;
        }
        break;
      case 3:
        printf("%s\n", buscar(x) == buscar(y) ? "YES" : "NO");
        break;
    }
  }
  return 0;
}
int buscar(int buscado) {
  return v[buscado] = v[buscado] == buscado ? buscado : buscar(v[buscado]);
}
