#include <bits/stdc++.h>
using namespace std;
void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int n, q;
vector<int> p, r;
int find(int u) {
  if (u == p[u]) return u;
  return p[u] = find(p[u]);
}
void solve() {
  cin >> n >> q;
  p.resize(n + 1);
  r.resize(n + 1);
  iota(r.begin(), r.end(), 1);
  iota(p.begin(), p.end(), 0);
  int tp, x, y;
  while (q--) {
    cin >> tp >> x >> y;
    if (tp == 1) {
      p[find(x)] = find(y);
    } else if (tp == 2) {
      int p1;
      for (int i = x + 1; i <= y; i = p1) {
        p[find(i - 1)] = find(y);
        p1 = r[i];
        r[i] = max(r[i], y + 1);
      }
    } else {
      if (find(x) == find(y))
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
  return;
}
int main() {
  boost();
  int tc = 1;
  while (tc--) solve();
  return 0;
}
