#include <bits/stdc++.h>
#pragma comment(linker, "/STATK:134217728")
using namespace std;
int n, q;
int p[1 << 18];
int r[1 << 18];
set<pair<int, int> > S;
void make(int x) {
  r[x] = 0;
  p[x] = x;
}
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x != y) {
    if (r[x] > r[y])
      p[y] = x;
    else {
      p[x] = y;
      if (r[x] == r[y]) ++r[y];
    }
  }
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; ++i) make(i);
  for (int i = 0; i < n; ++i) S.insert(make_pair(i, i + 1));
  while (q-- > 0) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    x--, y--;
    if (t == 1)
      unite(x, y);
    else if (t == 2) {
      while (1) {
        set<pair<int, int> >::iterator it = S.upper_bound(make_pair(x, n));
        it--;
        if (it->second <= y) {
          unite(x, it->second);
          int L = it->first;
          S.erase(it);
          it = S.upper_bound(make_pair(x, n));
          int R = it->second;
          S.erase(it);
          S.insert(make_pair(L, R));
        } else
          break;
      }
    } else {
      if (find(x) == find(y))
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
