#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10000;
int par[maxn], nx[maxn];
int getPar(int x) {
  if (par[x] == x) return x;
  return par[x] = getPar(par[x]);
}
int getNx(int x) {
  if (nx[x] == x) return x;
  return nx[x] = getNx(nx[x]);
}
void merge(int x, int y) {
  x = getPar(x), y = getPar(y);
  par[x] = y;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++) par[i] = i, nx[i] = i;
  while (m--) {
    int q, x, y;
    scanf("%d%d%d", &q, &x, &y);
    x--, y--;
    if (q == 1) {
      merge(x, y);
    } else if (q == 2) {
      for (int i = getNx(x); i < y; i = getNx(i + 1)) {
        merge(x, i + 1);
        nx[i] = i + 1;
      }
    } else {
      if (getPar(x) == getPar(y))
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
}
