#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const long long inf = 0x3f3f3f3f3f3f3f3fLL;
const long long N = 3e5 + 10;
const long long MOD = 1e9 + 7;
long long par[N];
long long find(long long x) {
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}
void uni(long long x, long long y) {
  x = find(x);
  y = find(y);
  par[x] = y;
}
long long n, q;
set<long long> s;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (long long i = 0; i < n; i++) par[i] = i;
  for (long long i = 0; i < n - 1; i++) s.insert(i);
  s.insert(inf);
  long long t, x, y;
  for (long long i = 0; i < q; i++) {
    cin >> t >> x >> y;
    x--, y--;
    if (t == 1)
      uni(x, y);
    else if (t == 2) {
      vector<long long> a;
      auto it = s.lower_bound(x);
      while (1) {
        if (*it >= y) break;
        a.push_back(*it);
        it++;
      }
      for (auto i : a) s.erase(i);
      for (long long i = 0; i < (long long)a.size(); i++) uni(a[i], a[i] + 1);
    } else {
      cout << (find(x) == find(y) ? "YES" : "NO") << '\n';
    }
  }
  return 0;
}
