#include <bits/stdc++.h>
using namespace std;
set<int> s;
int p[323456];
int find(int u) { return p[u] == u ? p[u] : p[u] = find(p[u]); }
void _union(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) p[a] = b;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    s.insert(i);
  }
  while (m--) {
    int ty, x, y;
    scanf("%d%d%d", &ty, &x, &y);
    if (ty == 1)
      _union(x, y);
    else if (ty == 2) {
      if (x > y) swap(x, y);
      set<int>::iterator it = s.lower_bound(x);
      while (it != s.end() && *it < y) {
        _union(*it, (*it) + 1);
        s.erase(it++);
      }
    } else {
      if (find(x) == find(y))
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
