#include <bits/stdc++.h>
using namespace std;
struct node {
  long long val;
  long long set;
  node() : val(0), set(-1) {}
};
const int MAX_N = 200050;
struct segtree {
  long long c;
  static const int OP_SET = 0;
  static const int OP_GET = 3;
  void actualize(int v) { t[v].val = min(t[2 * v + 1].val, t[2 * v + 2].val); }
  void push(int v) {
    long long tmp = c;
    if (t[v].set != -1) {
      c = t[v].set;
      mod_set(2 * v + 1);
      mod_set(2 * v + 2);
      t[v].set = -1;
    }
    c = tmp;
  }
  long long update(int l, int r, int v, int tl, int tr, int op) {
    if (l >= r) {
      return 0;
    }
    if (l == tl && r == tr) {
      switch (op) {
        case OP_SET:
          mod_set(v);
          break;
      }
      return t[v].val;
    }
    push(v);
    int mid = (tl + tr) / 2;
    long long lres = update(l, min(mid, r), 2 * v + 1, tl, mid, op);
    long long rres = update(max(mid, l), r, 2 * v + 2, mid, tr, op);
    actualize(v);
    return max(lres, rres);
  }
  void mod_set(int v) {
    t[v].val = c;
    t[v].set = c;
  }
  node t[4 * MAX_N];
};
segtree tr;
int n;
int rang[MAX_N];
int parent[MAX_N];
void make_set(int v) {
  parent[v] = v;
  rang[v] = 0;
}
int find_set(int v) {
  if (v == parent[v]) return v;
  return 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;
    if (rang[a] == rang[b]) ++rang[a];
  }
}
int main() {
  int q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    make_set(i);
    tr.c = i + 1;
    tr.update(i, i + 1, 0, 0, n, tr.OP_SET);
  }
  for (int i = 0; i < q; ++i) {
    int type, x, y;
    scanf("%d %d %d", &type, &x, &y);
    --x;
    --y;
    switch (type) {
      case 1:
        union_sets(x, y);
        break;
      case 2:
        for (int i = x; i <= y; i = tr.update(i, i + 1, 0, 0, n, tr.OP_GET)) {
          union_sets(x, i);
        }
        tr.c = tr.update(y, y + 1, 0, 0, n, tr.OP_GET);
        tr.update(x, y + 1, 0, 0, n, tr.OP_SET);
        break;
      case 3:
        if (find_set(x) == find_set(y)) {
          cout << "YES" << endl;
        } else {
          cout << "NO" << endl;
        }
        break;
      default:
        break;
    }
  }
  return 0;
}
