#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 228;
int par[N], par1[N];
int get(int v) {
  if (par[v] != v) {
    par[v] = get(par[v]);
  }
  return par[v];
}
void join(int v, int u) {
  v = get(v);
  u = get(u);
  if (v == u) {
    return;
  }
  if (v > u) {
    par[u] = v;
  } else {
    par[v] = u;
  }
}
int get1(int v) {
  if (par1[v] != v) {
    par1[v] = get1(par1[v]);
  }
  return par1[v];
}
void join1(int v, int u) {
  v = get1(v);
  u = get1(u);
  if (v == u) {
    return;
  }
  if (v > u) {
    par1[u] = v;
  } else {
    par1[v] = u;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    par[i] = par1[i] = i;
  }
  for (int i = 0; i < q; ++i) {
    int t, x, y;
    cin >> t >> x >> y;
    x--;
    y--;
    if (t == 1) {
      join(x, y);
    }
    if (t == 2) {
      while ((x = get1(x)) < y) {
        join(x, x + 1);
        join1(x, x + 1);
      }
    }
    if (t == 3) {
      if (get(x) == get(y)) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    }
  }
  return 0;
}
