#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.141592653589793238462643383279502884;
const long long xd[] = {-1, 0, 1, 0};
const long long yd[] = {0, -1, 0, 1};
long long XX[] = {-1, -1, -1, 0, 0, 1, 1, 1};
long long YY[] = {-1, 0, 1, -1, 1, -1, 0, 1};
long long expo(long long a, long long b, long long m);
long long mmi(long long a, long long m);
void ipgraph(long long m);
const long long N = 5 * (1e5) + 10;
vector<vector<long long> > adj(N);
long long par[N], ran[N];
void make_set(long long n) {
  for (long long i = 0; i < n; i++) par[i] = i, ran[i] = 0;
}
long long find_set(long long u) {
  if (u == par[u]) return u;
  return par[u] = find_set(par[u]);
}
void union_set(long long u, long long v) {
  long long x = find_set(u);
  long long y = find_set(v);
  if (x == y) return;
  if (ran[x] > ran[y]) swap(x, y);
  par[x] = y;
  if (ran[x] == ran[y]) ran[y]++;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, q;
  cin >> n >> q;
  set<long long> s;
  make_set(n);
  for (long long i = 0; i < n; i++) s.insert(i);
  while (q--) {
    long long t, u, v;
    cin >> t >> u >> v, u--, v--;
    if (t == 1) {
      union_set(u, v);
    } else if (t == 2) {
      auto it = s.upper_bound(u);
      while (it != s.end() && (*it) <= v) {
        union_set(u, *it);
        s.erase(it);
        it = s.upper_bound(u);
      }
    } else {
      if (find_set(u) == find_set(v))
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
  return 0;
}
void ipgraph(long long m) {
  long long i, u, v;
  while (m--) {
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
}
long long expo(long long a, long long b, long long m) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long val = (expo(a, b / 2, m) * expo(a, b / 2, m)) % m;
  if (b & 1)
    return (val * a) % m;
  else
    return val;
}
long long mmi(long long a, long long m) { return expo(a, m - 2, m); }
