#include <bits/stdc++.h>
using namespace std;
int n, m, root[200005], nxt[200005];
int get(int u) { return root[u] == u ? u : root[u] = get(root[u]); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) nxt[i] = i + 1, root[i] = i;
  for (int i = 1; i <= m; i++) {
    int t, u, v, x, y;
    cin >> t >> u >> v;
    x = get(u);
    y = get(v);
    if (t == 1) root[x] = y;
    if (t == 3) cout << ((x == y) ? "YES\n" : "NO\n");
    if (t == 2) {
      for (int i = u; i <= v;) {
        root[get(i)] = y;
        int x = i;
        i = nxt[i];
        nxt[x] = nxt[v];
      }
    }
  }
  return 0;
}
