#include <bits/stdc++.h>
using namespace std;
int cnt[200000 + 5];
set<int> S;
pair<int, int> V[200000 + 5];
int find(int x) {
  if (V[x].first != x) V[x].first = find(V[x].first);
  return V[x].first;
}
void Union(int x, int y) {
  int xpar = find(x);
  int ypar = find(y);
  if (xpar == ypar) return;
  if (V[xpar].second > V[ypar].second) {
    V[ypar].first = xpar;
    cnt[xpar] += cnt[ypar];
  } else if (V[xpar].second < V[ypar].second) {
    V[xpar].first = ypar;
    cnt[ypar] += cnt[xpar];
  } else {
    V[ypar].first = xpar;
    cnt[xpar] += cnt[ypar];
    V[xpar].second++;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int i, j, n, q, ty, x, y;
  cin >> n >> q;
  for (i = 1; i <= n; i++) {
    V[i] = {i, 0};
    cnt[i] = 1;
    S.insert(i);
  }
  while (q--) {
    cin >> ty >> x >> y;
    if (ty == 1) {
      Union(x, y);
    } else if (ty == 2) {
      auto it1 = S.upper_bound(x);
      auto it2 = S.upper_bound(y);
      vector<int> dele;
      for (auto it = it1; it != it2; it++) {
        dele.push_back(*it);
      }
      int p = *prev(it1);
      for (i = 0; i < dele.size(); i++) {
        int z = dele[i];
        Union(p, z);
        S.erase(z);
      }
    } else {
      if (find(x) == find(y))
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
  return 0;
}
