#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)3e5;
int parent[MAXN], rang[MAXN], nxt[MAXN];
void make_set(int v) {
  parent[v] = v;
  rang[v] = 1;
  nxt[v] = v + 1;
}
int find_set(int v) {
  return (parent[v] == v ? v : parent[v] = find_set(parent[v]));
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (rang[a] < rang[b]) swap(a, b);
    parent[b] = a;
    rang[a] += rang[b];
  }
}
int n, q;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) make_set(i);
  while (q--) {
    int c, x, y;
    cin >> c >> x >> y;
    switch (c) {
      case 1: {
        union_sets(x, y);
        break;
      }
      case 2: {
        for (int i = x, j; i <= y; j = i, i = nxt[i], nxt[j] = nxt[y])
          union_sets(x, i);
        break;
      }
      case 3: {
        cout << (find_set(x) == find_set(y) ? "YES" : "NO") << endl;
        break;
      }
    }
  }
  return 0;
}
