#include <bits/stdc++.h>
using namespace std;
const long long maxm = 2e5 + 5;
long long pre[maxm];
long long r[maxm];
long long n, q;
long long ffind(long long x) {
  return pre[x] == x ? x : pre[x] = ffind(pre[x]);
}
signed main() {
  ios::sync_with_stdio(0);
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) {
    pre[i] = i;
    r[i] = i + 1;
  }
  while (q--) {
    long long op;
    cin >> op;
    long long x, y;
    cin >> x >> y;
    if (op == 1) {
      pre[ffind(y)] = ffind(x);
    } else if (op == 2) {
      long long rt = ffind(y);
      for (long long i = x; i <= y;) {
        pre[ffind(i)] = rt;
        long long nt = r[i];
        r[i] = r[y];
        i = nt;
      }
    } else if (op == 3) {
      if (ffind(x) == ffind(y))
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
