#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector")
using namespace std;
int n, q;
int type, x, y;
vector<int> parent, ra_nk, range;
void make_set(int x) {
  parent[x] = x;
  ra_nk[x] = 1;
  range[x] = x;
}
int find_range(int v) {
  if (range[v] == v) return v;
  return range[v] = find_range(range[v]);
}
int find_set(int v) {
  if (parent[v] == v) return v;
  return parent[v] = find_set(parent[v]);
}
void union_set(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a == b) return;
  if (ra_nk[a] < ra_nk[b]) swap(a, b);
  parent[b] = a;
  ra_nk[a] += ra_nk[b];
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int test = 1;
  while (test--) {
    scanf("%d%d", &n, &q);
    parent.assign(200005, 0);
    ra_nk.assign(200005, 0);
    range.assign(200005, 0);
    for (int i = 0; i <= 200005; i++) make_set(i);
    while (q--) {
      scanf("%d%d%d", &type, &x, &y);
      if (type == 1) {
        union_set(x, y);
      } else if (type == 2) {
        while (x < y) {
          x = find_range(x);
          if (x >= y) break;
          union_set(x, x + 1);
          range[x] = y;
          x++;
        }
      } else {
        x = find_set(x);
        y = find_set(y);
        if (x == y)
          printf("YES\n");
        else
          printf("NO\n");
      }
    }
  }
  cerr << endl
       << "Time: " << (clock() * 1000. / CLOCKS_PER_SEC) << " ms" << endl;
  return 0;
}
