#include <bits/stdc++.h>
using namespace std;
vector<int> dsu;
vector<int> srank;
vector<int> dsu_seg;
vector<int> srank_seg;
vector<int> border;
void build_dsu(int n) {
  dsu.assign(n + 1, 0);
  srank.assign(n + 1, 1);
  dsu_seg.assign(n + 1, 0);
  srank_seg.assign(n + 1, 1);
  border.assign(n + 1, 0);
  for (int i = 0; i <= n; i++) {
    dsu[i] = i;
    dsu_seg[i] = i;
    border[i] = i;
  }
}
int find_set(int v) {
  if (v == dsu[v]) return v;
  return dsu[v] = find_set(dsu[v]);
}
int find_set_seg(int v) {
  if (v == dsu_seg[v]) return v;
  return dsu_seg[v] = find_set_seg(dsu_seg[v]);
}
void unite(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a == b) return;
  if (srank[a] < srank[b]) swap(a, b);
  swap(a, b);
  srank[a] += srank[b];
  dsu[b] = a;
}
void unite_seg(int a, int b) {
  a = find_set_seg(a);
  b = find_set_seg(b);
  if (a == b) return;
  if (srank_seg[a] < srank_seg[b]) swap(a, b);
  dsu_seg[b] = a;
  srank_seg[a] += srank_seg[b];
  border[a] = max(border[a], border[b]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  build_dsu(n);
  for (int i = 0; i < q; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      unite(x, y);
    } else if (t == 2) {
      for (int r = border[find_set_seg(x)]; r <= y - 1;
           r = border[find_set_seg(r)]) {
        unite(r, r + 1);
        unite_seg(r, r + 1);
      }
    } else {
      if (find_set(x) == find_set(y)) {
        cout << "YES" << '\n';
      } else {
        cout << "NO" << '\n';
      }
    }
  }
}
