#include <bits/stdc++.h>
template <int N>
struct DSET {
  int s[N];
  int f(int x) { return s[x] == x ? x : s[x] = f(s[x]); }
  bool same(int x, int y) { return f(x) == f(y); }
  void u(int x, int y) {
    x = f(x), y = f(y);
    if (x != y) s[y] = x;
  }
  void init(int n) {
    for (int i = 0; i < n; i++) {
      s[i] = i;
    }
  }
};
int main() {
  int i, j, k;
  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    static DSET<200001> a, b;
    a.init(n);
    b.init(n);
    while (m--) {
      int type, x, y;
      scanf("%d", &type);
      scanf("%d", &x);
      scanf("%d", &y);
      x--;
      y--;
      if (type == 1) {
        a.u(b.f(x), b.f(y));
        a.u(x, y);
      } else if (type == 2) {
        for (int t = b.f(y) - 1; t >= x; t = b.f(t) - 1) {
          a.u(t, y);
          b.u(t, y);
        }
      } else {
        puts(a.same(x, y) || b.same(x, y) ? "YES" : "NO");
      }
    }
  }
}
