#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1, logn = 20;
int p[N], r[N], nxt[N];
int getparent(int v) { return v == p[v] ? v : p[v] = getparent(p[v]); }
void un(int a, int b) {
  a = getparent(a);
  b = getparent(b);
  if (a != b) {
    if (r[a] < r[b]) swap(a, b);
    p[b] = a;
    if (r[a] == r[b]) r[a]++;
  }
}
bool otdel(int a, int b) {
  a = getparent(a);
  b = getparent(b);
  return a == b;
}
void unionSegment(int l, int r) {
  int i = l;
  while (i < r) {
    un(i, i + 1);
    int t = i;
    i = nxt[i];
    nxt[t] = r;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, q;
  cin >> n >> q;
  for (int v = 1; v <= n; v++) p[v] = v, r[v] = 0, nxt[v] = v + 1;
  while (q--) {
    int type;
    cin >> type;
    int a, b;
    cin >> a >> b;
    if (type == 1)
      un(a, b);
    else if (type == 3)
      cout << (otdel(a, b) ? "YES" : "NO") << '\n';
    else
      unionSegment(a, b);
  }
}
