#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, p;
int fa[200010], nxt[200010];
int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
void merge(int u, int v) {
  int fx = getfa(u);
  int fy = getfa(v);
  if (fx != fy) fa[fx] = fy;
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i, nxt[i] = i + 1;
  while (m--) {
    scanf("%d%d%d", &p, &x, &y);
    if (p == 1) merge(x, y);
    if (p == 2) {
      int t;
      for (int i = x; i <= y; i = t) {
        merge(i, y);
        t = nxt[i];
        nxt[i] = nxt[y];
      }
    }
    if (p == 3) puts(fa[getfa(x)] == fa[getfa(y)] ? "YES" : "NO");
  }
  return 0;
}
