#include <bits/stdc++.h>
using namespace std;
vector<int> p;
set<int> st;
int n;
int get_next(int v) {
  if (p[v] == v) {
    return v;
  }
  return p[v] = get_next(p[v]);
  ;
}
void unite(int a, int b) {
  a = get_next(a);
  b = get_next(b);
  if (a != b) {
    if (rand() & 1) {
      swap(a, b);
    }
    p[a] = b;
  }
}
int main() {
  int q;
  scanf("%d%d", &n, &q);
  p.resize(n);
  for (int i = 0; i < n; ++i) {
    p[i] = i;
  }
  for (int i = 0; i < n; ++i) {
    st.insert(i);
  }
  while (q--) {
    int type, x, y;
    scanf("%d%d%d", &type, &x, &y);
    --x;
    --y;
    if (type == 1) {
      unite(x, y);
    } else if (type == 2) {
      set<int>::iterator from = st.lower_bound(x), to = st.lower_bound(y);
      for (set<int>::iterator it = from; it != to; ++it) {
        int ind = *it;
        unite(ind, ind + 1);
      }
      if (from != to) {
        st.erase(from, to);
      }
    } else {
      if (get_next(x) == get_next(y)) {
        printf("YES\n");
      } else {
        printf("NO\n");
      }
    }
  }
  return 0;
}
