#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int p[N], r[N], nx[N];
int find_(int v) { return v == p[v] ? v : p[v] = find_(p[v]); }
int co(int v) { return v == nx[v] ? v : nx[v] = co(nx[v]); }
void unite(int a, int b) {
  a = find_(a);
  b = find_(b);
  if (a != b) {
    if (r[a] < r[b]) swap(a, b);
    if (r[a] == r[b]) r[a]++;
    p[b] = a;
  }
}
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    nx[i] = i;
    p[i] = i;
    r[i] = 0;
  }
  for (int i = 0; i < q; i++) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    x--;
    y--;
    if (t == 1)
      unite(x, y);
    else if (t == 3)
      if (find_(x) == find_(y))
        printf("YES\n");
      else
        printf("NO\n");
    else {
      for (int i = x; i < y;) {
        i = co(nx[i]);
        if (i >= y) break;
        unite(i, i + 1);
        nx[i] = i + 1;
      }
    }
  }
  return 0;
}
