#include <bits/stdc++.h>
#define ll int
#define el "\n"
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define __ROOT__ int main()
#define fi first
#define se second
#define M 1000000007
#define MAXN 1000001
using namespace std;

ll n, q;
ll arr[MAXN], sz[MAXN], par[MAXN], next_pos[MAXN];

ll find_set(ll a) {
    if (a == par[a]) return a;
    return par[a] = find_set(par[a]);
}

void union_set(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a == b) return;
    if (sz[a] < sz[b]) swap(a, b);
    par[b] = a;
    sz[a] += sz[b];
}

void init() {
    cin >> n >> q;
    for (ll i = 1; i <= n; i++) {
        par[i] = i;
        sz[i] = 1;
        next_pos[i] = i + 1;
    }
}

void merge_range(ll x, ll y ){
while(x<= y){
    union_set(x,x+1) ;
    ll t = x;
    x = next_pos[x] ; // bỏ qua các vị trí đã hợp
    next_pos[t] = y +1 ;
}
}

void solve() {
    while (q--) {
        ll t, x, y;
        cin >> t >> x >> y;
        if (t == 1) {
            union_set(x, y);
        } else if (t == 2) {
            merge_range(x, y);
        } else {
            x = find_set(x);
            y = find_set(y);
            if (x == y) {
                cout << "YES" << el;
            } else {
                cout << "NO" << el;
            }
        }
    }
}

__ROOT__ {
    fast;
    init();
    solve();
}
