#include <bits/stdc++.h>
using namespace std;
int P[200005], V[200005];
int root(int x) {
  if (P[x] == x) return x;
  return P[x] = root(P[x]);
}
void merge(int x, int y) {
  x = root(x), y = root(y);
  P[y] = x;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  for (int i = 1; i <= N; i++) P[i] = i, V[i] = i + 1;
  for (int i = 1; i <= Q; i++) {
    int type, x, y;
    cin >> type >> x >> y;
    if (type == 1)
      merge(x, y);
    else if (type == 2) {
      int id = x;
      while (id < y) {
        merge(id, x);
        int t = V[id];
        V[id] = y;
        id = t;
      }
      merge(y, x);
    } else {
      if (root(x) == root(y))
        cout << "YES"
             << "\n";
      else
        cout << "NO"
             << "\n";
    }
  }
  return 0;
}
