#include <bits/stdc++.h>
using namespace std;
vector<int> otec, range, sotec, srange, sst, send;
int get_otec(int a) {
  if (otec[a] == -1) return a;
  return otec[a] = get_otec(otec[a]);
}
int get_sotec(int a) {
  if (sotec[a] == -1) return a;
  return sotec[a] = get_sotec(sotec[a]);
}
void merge(int a, int b) {
  a = get_otec(a);
  b = get_otec(b);
  if (a == b) return;
  if (range[a] < range[b]) swap(a, b);
  otec[b] = a;
  range[a] += range[b];
}
void smerge(int a, int b) {
  a = get_sotec(a);
  b = get_sotec(b);
  if (a == b) return;
  if (srange[a] < srange[b]) swap(a, b);
  sotec[b] = a;
  srange[a] += srange[b];
  sst[a] = min(sst[a], sst[b]);
  send[a] = max(send[a], send[b]);
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  otec = vector<int>(n, -1);
  range = vector<int>(n, 1);
  sotec = vector<int>(n, -1);
  srange = vector<int>(n, 1);
  sst = vector<int>(n);
  send = vector<int>(n);
  for (int i = 0; i < n; i++) {
    sst[i] = i;
    send[i] = i + 1;
  }
  for (int i = 0; i < q; i++) {
    int t, x, y;
    scanf("%d %d %d", &t, &x, &y);
    x--;
    y--;
    switch (t) {
      case 1: {
        merge(x, y);
        break;
      }
      case 2: {
        while (send[get_sotec(x)] <= y) {
          int on = send[get_sotec(x)];
          smerge(x, on);
          merge(x, on);
        }
        break;
      }
      case 3: {
        if (get_otec(x) == get_otec(y))
          printf("YES\n");
        else
          printf("NO\n");
        break;
      }
    }
  }
  return 0;
}
