#include <bits/stdc++.h>
using namespace std;
long long t, n, m, u, v, q, r, ql, qr, k, l, s, w, h, c, z, d, y, x;
const int N = 2e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 62LL;
const bool JUDGE = false;
int P1[N], P2[N];
int find(int P[], int x) { return P[x] = (x == P[x] ? x : find(P, P[x])); }
inline void unite(int P[], int x, int y) {
  x = find(P, x);
  y = find(P, y);
  if (x == y) return;
  if (x > y)
    P[y] = x;
  else
    P[x] = y;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (JUDGE) {
    freopen("angry.in", "r", stdin);
    freopen("angry.out", "w", stdout);
  }
  cin >> n >> q;
  for (int i = 1; i <= n + 1; ++i) {
    P1[i] = P2[i] = i;
  }
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      cin >> x >> y;
      unite(P1, x, y);
    } else if (type == 2) {
      cin >> x >> y;
      x = find(P2, x);
      while (x < y) {
        unite(P1, x, x + 1);
        unite(P2, x, x + 1);
        x = find(P2, x);
      }
    } else {
      cin >> x >> y;
      x = find(P1, x);
      y = find(P1, y);
      if (x == y)
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
  return 0;
}
