#include <bits/stdc++.h>
using namespace std;
int n, q, x, y, c;
const int LIM = 2e5 + 5;
int par[LIM];
int rk[LIM];
set<int> st;
int getpar(int i) { return (par[i] == i) ? i : (par[i] = getpar(par[i])); }
void join(int i, int j) {
  i = getpar(i);
  j = getpar(j);
  if (i == j) return;
  if (rk[i] > rk[j]) {
    par[j] = i;
    rk[i] += rk[j];
  } else {
    par[i] = j;
    rk[j] += rk[i];
  }
}
void join2(int i, int j) {
  auto it = st.upper_bound(i);
  while (it != st.end() && (*it) <= j) {
    join(i, *it);
    int val = *it;
    st.erase(it);
    it = st.upper_bound(val);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i < n + 1; ++i) rk[i] = 1, par[i] = i, st.insert(i);
  for (int i = 0; i < q; ++i) {
    cin >> c >> x >> y;
    if (c == 1) {
      join(x, y);
    } else if (c == 2) {
      join2(x, y);
    } else {
      cout << ((getpar(x) == getpar(y)) ? "YES" : "NO") << "\n";
    }
  }
}
