#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, q, nxt[N], par[N];
int fn(int x) { return par[x] == x ? x : par[x] = fn(par[x]); }
int jump(int x) { return nxt[x] == x ? x : nxt[x] = jump(nxt[x]); }
void enter() {
  cin >> n >> q;
  for (int i = (1), c = (n + 1); i <= c; ++i) {
    par[i] = nxt[i] = i;
  }
}
void process() {
  int typ, x, y;
  while (q--) {
    scanf("%d %d %d\n", &typ, &x, &y);
    if (typ == 1) {
      par[fn(x)] = fn(y);
    } else if (typ == 2) {
      for (x = jump(x); x < y; x = jump(x)) {
        par[fn(x)] = fn(x + 1);
        nxt[x] = x + 1;
      }
    } else if (typ == 3) {
      if (fn(x) == fn(y))
        puts("YES");
      else
        puts("NO");
    }
  }
}
int main() {
  enter();
  process();
  return 0;
}
