#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 10, mod = 1e9, inf = 2e9;
long long par[maxn], siz[maxn], ans, b[maxn];
vector<pair<long long, pair<long long, long long>>> vv;
long long ss[maxn];
int root(long long a) {
  if (par[a] == a) {
    return a;
  }
  par[a] = root(par[a]);
  return root(par[a]);
}
int root2(long long a) {
  if (b[a] == a) {
    return a;
  }
  b[a] = root2(b[a]);
  return root2(b[a]);
}
int unionn(long long x, long long y) {
  long long x2 = root(x);
  long long y2 = root(y);
  if (x2 == y2) {
    return 0;
  }
  siz[y2] += siz[x2];
  par[x2] = y2;
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    siz[i] = 1;
    par[i] = i;
    b[i] = i;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long ss, x, y;
    cin >> ss >> x >> y;
    if (ss == 1) {
      unionn(x, y);
    }
    if (ss == 2) {
      long long l = x;
      long long r = y + 1;
      while (l + 1 < r) {
        long long mid = (r + l) / 2;
        if (root2(mid) > root2(x)) {
          r = mid;
        } else {
          l = mid;
        }
      }
      y = root2(y);
      for (int j = l; j <= y - 1; j++) {
        unionn(j, j + 1);
        b[j + 1] = b[x];
      }
    }
    if (ss == 3) {
      if (root(x) == root(y)) {
        cout << "YES" << endl;
      } else
        cout << "NO" << endl;
    }
  }
}
