#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[500001];
int t[500001];
void init() {
  int i;
  for (i = 1; i <= n; i++) {
    f[i] = i;
    t[i] = i + 1;
  }
}
int getf(int u) {
  if (u != f[u]) return f[u] = getf(f[u]);
  return u;
}
void merge(int v, int u) {
  int t1 = getf(v);
  int t2 = getf(u);
  if (t1 != t2) f[t2] = t1;
}
int main() {
  int a, b, c;
  while (cin >> n >> m) {
    init();
    while (m--) {
      cin >> a >> b >> c;
      if (a == 1)
        merge(b, c);
      else if (a == 2) {
        int temp;
        for (int i = b + 1; i <= c; i = temp) {
          merge(i, i - 1);
          temp = t[i];
          t[i] = c + 1;
        }
      } else {
        if (getf(b) != getf(c))
          cout << "NO" << endl;
        else
          cout << "YES" << endl;
      }
    }
  }
  return 0;
}
