#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
struct DIS {
  int f[MAXN];
  void init(int n) {
    for (int i = 1; i <= n; i++) f[i] = i;
  }
  int find(int x) {
    if (f[x] == x) return x;
    return f[x] = find(f[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  void Union(int x, int y) {
    if (!same(x, y)) f[f[x]] = f[y];
  }
} dis;
int ch[MAXN];
int main() {
  int n, q, o, x, y;
  scanf("%d%d", &n, &q);
  dis.init(n);
  for (int i = 1; i <= n; i++) ch[i] = i;
  while (q--) {
    scanf("%d%d%d", &o, &x, &y);
    if (o == 1)
      dis.Union(x, y);
    else if (o == 2) {
      for (int i = ch[x] + 1, lst = x; i <= y; lst = i, i = ch[i] + 1) {
        dis.Union(lst, i);
        ch[lst] = y;
      }
    } else if (o == 3)
      puts(dis.same(x, y) ? "YES" : "NO");
    else
      assert(0);
  }
  return 0;
}
