#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T> >;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 2e5 + 10;
const int inf = 1e9;
int n, q;
int p[maxN], rnk[maxN];
set<int> st;
void init() {
  st.emplace(inf);
  for (int i = 1; i <= (int)(n); ++i) {
    p[i] = i;
    rnk[i] = 1;
    st.emplace(i);
  }
}
int root(int u) { return u == p[u] ? u : p[u] = root(p[u]); }
bool unify(int u, int v) {
  u = root(u);
  v = root(v);
  if (u == v) {
    return 0;
  }
  if (rnk[u] < rnk[v]) {
    swap(u, v);
  }
  p[v] = u;
  if (rnk[u] == rnk[v]) {
    ++rnk[u];
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> q;
  init();
  while (q--) {
    int type, x, y;
    cin >> type >> x >> y;
    if (type == 1) {
      unify(x, y);
    } else if (type == 2) {
      auto it = st.lower_bound(x);
      vector<int> tmp;
      while (1) {
        if ((*it) >= y) {
          break;
        }
        tmp.emplace_back(*it);
        ++it;
      }
      for (auto &d : tmp) {
        st.erase(d);
        unify(d, d + 1);
      }
    } else {
      cout << (root(x) == root(y) ? "YES\n" : "NO\n");
    }
  }
  return 0;
}
