#include <bits/stdc++.h>
int father[200001];
int next[200001];
int find(int x) {
  if (x == father[x]) return x;
  return father[x] = find(father[x]);
}
void swap(int &a, int &b) {
  int t = a;
  a = b;
  b = t;
}
int main() {
  int n, k, i, j, t, x, y;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) {
    father[i] = i;
    next[i] = i + 1;
  }
  for (j = 1; j <= k; j++) {
    scanf("%d %d %d", &t, &x, &y);
    if (t == 1) {
      if (x > y) swap(x, y);
      father[find(y)] = find(x);
      if (y - x == 1) next[x] = next[y];
    } else if (t == 2) {
      int f = find(x), next_p;
      for (i = x + 1; i <= y; i = next_p) {
        father[find(i)] = f;
        next_p = next[i];
        next[i] = next[y];
      }
    } else if (t == 3 && find(x) == find(y))
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
