#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T BM(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T MDINV(T a, T M) {
  return BM(a, M - 2, M);
}
template <class T>
inline T PW(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
template <class T>
string NTS(T Number) {
  stringstream ss;
  ss << Number;
  return ss.str();
}
template <class T>
T stringtonumber(const string &Text) {
  istringstream ss(Text);
  T result;
  return ss >> result ? result : 0;
}
int par[200005];
int seg[200005];
int fin1(int x) {
  if (x == par[x]) return x;
  return par[x] = fin1(par[x]);
}
int fin2(int x) {
  if (x == seg[x]) return x;
  return seg[x] = fin2(seg[x]);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) seg[i] = i, par[i] = i;
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    if (x == 1) {
      int u = fin1(y);
      int v = fin1(z);
      if (u != v) par[u] = v;
    } else if (x == 2) {
      if (y > z) swap(y, z);
      int st = y;
      while (st < z) {
        int u = fin2(st);
        int v = fin2(z);
        if (u != v) {
          st = u;
        }
        v = fin2(st + 1);
        seg[st] = v;
        int l = v;
        u = fin1(st);
        v = fin1(st + 1);
        if (u != v) par[u] = v;
        st = l;
      }
    } else {
      int u = fin1(y);
      int v = fin1(z);
      if (u == v)
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
