#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int fa[300010], nxt[300010];
int find(int x) {
  if (fa[x] != x) fa[x] = find(fa[x]);
  return fa[x];
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) fa[i] = i, nxt[i] = i + 1;
  while (m--) {
    int op, a, b;
    scanf("%d%d%d", &op, &a, &b);
    if (a > b) swap(a, b);
    if (op == 1) {
      int u = find(a), v = find(b);
      if (u == v) continue;
      fa[u] = v;
    } else if (op == 2) {
      for (int i = a, j = nxt[i]; j <= b; i = j, j = nxt[i]) {
        int u = find(i), v = find(j);
        nxt[i] = nxt[j];
        if (u == v) continue;
        fa[u] = v;
      }
    } else {
      if (find(a) == find(b))
        puts("YES");
      else
        puts("NO");
    }
  }
  return 0;
}
