#include <bits/stdc++.h>
long long int nxt[200005];
struct subset {
  long long int parent, rank;
};
struct subset *subsets;
long long int find(long long int i) {
  if (subsets[i].parent != i) {
    subsets[i].parent = find(subsets[i].parent);
  }
  return subsets[i].parent;
}
void unin(long long int x, long long int y) {
  long long int xroot = find(x);
  long long int yroot = find(y);
  if (subsets[xroot].rank < subsets[yroot].rank) {
    subsets[xroot].parent = yroot;
  } else if (subsets[xroot].rank > subsets[yroot].rank) {
    subsets[yroot].parent = xroot;
  } else {
    subsets[yroot].parent = xroot;
    subsets[xroot].rank++;
  }
}
long long int recur(long long int x, long long int y, long long int z) {
  if (y <= x || y < z) {
    if (find(x) != find(z)) {
      return z;
    }
    nxt[x] = recur(z, y, nxt[z]);
    return nxt[x];
  } else if (find(x) != find(z)) {
    unin(x, z);
  }
  nxt[x] = recur(z, y, nxt[z]);
  return nxt[x];
}
int main() {
  long long int n, q, type, x, y, i;
  scanf("%lld%lld", &n, &q);
  subsets = (struct subset *)malloc((n + 5) * sizeof(struct subset));
  for (i = 1; i <= n + 1; i++) {
    subsets[i].parent = i;
    subsets[i].rank = 0;
    nxt[i] = i + 1;
  }
  while (q--) {
    scanf("%lld%lld%lld", &type, &x, &y);
    if (type == 1) {
      if (find(x) != find(y)) unin(x, y);
    } else if (type == 2) {
      recur(x, y, x + 1);
    } else {
      printf("%s\n", find(x) == find(y) ? "YES" : "NO");
    }
  }
  return 0;
}
