#include <bits/stdc++.h>
using namespace std;
struct person {
  int rank;
  int boss;
  int skip_to;
};
person **sets;
int findBoss(int p) {
  if (sets[p]->boss == p) return p;
  int b = findBoss(sets[p]->boss);
  sets[p]->boss = b;
  return b;
}
void merge(int p, int q) {
  int b1 = findBoss(p);
  int b2 = findBoss(q);
  if (b1 == b2) return;
  if (sets[b1]->rank > sets[b2]->rank) {
    sets[b2]->boss = b1;
  } else if (sets[b1]->rank < sets[b2]->rank) {
    sets[b1]->boss = b2;
  } else {
    sets[b1]->boss = b2;
    sets[b2]->rank++;
  }
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  sets = (person **)malloc(n * sizeof(person *));
  for (int i = 0; i < n; i++) {
    person *P = new person;
    P->rank = 0;
    P->skip_to = i + 1;
    P->boss = i;
    sets[i] = P;
  }
  for (int i = 0; i < q; i++) {
    int type, x, y;
    scanf("%d %d %d", &type, &x, &y);
    x--;
    y--;
    if (type == 1) {
      merge(x, y);
    } else if (type == 2) {
      int index = x;
      while (index <= y) {
        merge(x, index);
        int temp = sets[index]->skip_to;
        sets[index]->skip_to = y + 1;
        index = temp;
      }
    } else {
      if (findBoss(x) == findBoss(y))
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
}
