#include <bits/stdc++.h>
using namespace std;
int find_set(int parent[], int p) {
  if (p != parent[p]) parent[p] = find_set(parent, parent[p]);
  return parent[p];
}
void merge_sets(int x, int y, int parent[]) {
  int px = find_set(parent, x);
  int py = find_set(parent, y);
  parent[px] = py;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int parent[200100], group[200100];
  int n, q, i, a, b, type, px, py;
  cin >> n >> q;
  for (i = 0; i <= n + 2; i++) {
    parent[i] = i;
    group[i] = i;
  }
  while (q--) {
    cin >> type >> a >> b;
    if (type == 1) {
      merge_sets(a, b, parent);
    } else if (type == 2) {
      for (i = find_set(group, a); i < b; i = find_set(group, i)) {
        merge_sets(i, i + 1, parent);
        merge_sets(i, i + 1, group);
      }
    } else if (type == 3) {
      px = find_set(parent, a);
      py = find_set(parent, b);
      if (px == py)
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
  return 0;
}
