#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, q;
int p[N], ne[N];
int find(int x) {
  if (p[x] != x) p[x] = find(p[x]);
  return p[x];
}
void merge(int x, int y) {
  int px = find(x), py = find(y);
  if (px != py) p[px] = py;
}
int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) p[i] = i, ne[i] = i + 1;
  while (q--) {
    int type, x, y;
    scanf("%d%d%d", &type, &x, &y);
    if (type == 1) {
      merge(x, y);
    } else if (type == 2) {
      int i = ne[x];
      while (i <= y) {
        merge(i, x);
        int t = ne[i];
        ne[i] = ne[y];
        i = t;
      }
    } else {
      puts(find(x) == find(y) ? "YES" : "NO");
    }
  }
  return 0;
}
