#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000007;
map<int, int> me;
vector<int> st[maxn];
int merg(int a, int b)
{
auto it1 = --me.upper_bound(a);
auto it2 = --me.upper_bound(b);
a = it1->second;
b = it2->second;
if(a == b)
return b;
if(st[a].size() > st[b].size())
swap(a, b);
for(auto it: st[a])
if(me.count(it))
me[it] = b;
for(auto it: st[a])
{
auto IT = --me.upper_bound(it);
if(IT->first != it)
continue;
st[b].push_back(it);
auto IT2 = IT;
IT2++;
while(IT2->second == IT->second)
IT2 = me.erase(IT2);
IT2 = IT;
IT2--;
if(IT2->second == IT->second)
me.erase(IT);
}
return b;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
for(int i = 0; i <= n + 1; i++)
me[i] = i;
for(int i = 0; i <= n + 1; i++)
st[i].push_back(i);
while(q--)
{
int t;
cin >> t;
if(t == 1)
{
int a, b;
cin >> a >> b;
merg(a, b);
}
if(t == 2)
{
int a, b;
cin >> a >> b;
vector<int> que;
auto it = --me.upper_bound(a);
while(it->first <= b)
que.push_back((it++)->second);
b = que[0];
for(int i = 1; i < que.size(); i++)
b = merg(b, que[i]);
}
if(t == 3)
{
int a, b;
cin >> a >> b;
auto it1 = --me.upper_bound(a);
auto it2 = --me.upper_bound(b);
if(it1->second == it2->second)
cout << "YES\n";
else
cout << "NO\n";
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IG1heG4gPSAxMDAwMDA3OwptYXA8aW50LCBpbnQ+IG1lOwp2ZWN0b3I8aW50PiBzdFttYXhuXTsKCmludCBtZXJnKGludCBhLCBpbnQgYikKewogICAgYXV0byBpdDEgPSAtLW1lLnVwcGVyX2JvdW5kKGEpOwogICAgYXV0byBpdDIgPSAtLW1lLnVwcGVyX2JvdW5kKGIpOwogICAgYSA9IGl0MS0+c2Vjb25kOwogICAgYiA9IGl0Mi0+c2Vjb25kOwogICAgaWYoYSA9PSBiKQogICAgICAgIHJldHVybiBiOwogICAgaWYoc3RbYV0uc2l6ZSgpID4gc3RbYl0uc2l6ZSgpKQogICAgICAgIHN3YXAoYSwgYik7CiAgICBmb3IoYXV0byBpdDogc3RbYV0pCiAgICAgICAgaWYobWUuY291bnQoaXQpKQogICAgICAgICAgICBtZVtpdF0gPSBiOwogICAgZm9yKGF1dG8gaXQ6IHN0W2FdKQogICAgewogICAgICAgIGF1dG8gSVQgPSAtLW1lLnVwcGVyX2JvdW5kKGl0KTsKICAgICAgICBpZihJVC0+Zmlyc3QgIT0gaXQpCiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIHN0W2JdLnB1c2hfYmFjayhpdCk7CiAgICAgICAgYXV0byBJVDIgPSBJVDsKICAgICAgICBJVDIrKzsKICAgICAgICB3aGlsZShJVDItPnNlY29uZCA9PSBJVC0+c2Vjb25kKQogICAgICAgICAgICBJVDIgPSBtZS5lcmFzZShJVDIpOwogICAgICAgIElUMiA9IElUOwogICAgICAgIElUMi0tOwogICAgICAgIGlmKElUMi0+c2Vjb25kID09IElULT5zZWNvbmQpCiAgICAgICAgICAgIG1lLmVyYXNlKElUKTsKICAgIH0KICAgIHJldHVybiBiOwp9CgppbnQgbWFpbigpCnsKICAgIC8vZnJlb3BlbigiaW5wdXQudHh0IiwgInIiLCBzdGRpbik7CiAgICAvL2ZyZW9wZW4oIm91dHB1dC50eHQiLCAidyIsIHN0ZG91dCk7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7CiAgICBpbnQgbiwgcTsKICAgIGNpbiA+PiBuID4+IHE7CiAgICBmb3IoaW50IGkgPSAwOyBpIDw9IG4gKyAxOyBpKyspCiAgICAgICAgbWVbaV0gPSBpOwogICAgZm9yKGludCBpID0gMDsgaSA8PSBuICsgMTsgaSsrKQogICAgICAgIHN0W2ldLnB1c2hfYmFjayhpKTsKICAgIHdoaWxlKHEtLSkKICAgIHsKICAgICAgICBpbnQgdDsKICAgICAgICBjaW4gPj4gdDsKICAgICAgICBpZih0ID09IDEpCiAgICAgICAgewogICAgICAgICAgICBpbnQgYSwgYjsKICAgICAgICAgICAgY2luID4+IGEgPj4gYjsKICAgICAgICAgICAgbWVyZyhhLCBiKTsKICAgICAgICB9CiAgICAgICAgaWYodCA9PSAyKQogICAgICAgIHsKICAgICAgICAgICAgaW50IGEsIGI7CiAgICAgICAgICAgIGNpbiA+PiBhID4+IGI7CiAgICAgICAgICAgIHZlY3RvcjxpbnQ+IHF1ZTsKICAgICAgICAgICAgYXV0byBpdCA9IC0tbWUudXBwZXJfYm91bmQoYSk7CiAgICAgICAgICAgIHdoaWxlKGl0LT5maXJzdCA8PSBiKQogICAgICAgICAgICAgICAgcXVlLnB1c2hfYmFjaygoaXQrKyktPnNlY29uZCk7CiAgICAgICAgICAgIGIgPSBxdWVbMF07CiAgICAgICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPCBxdWUuc2l6ZSgpOyBpKyspCiAgICAgICAgICAgICAgICBiID0gbWVyZyhiLCBxdWVbaV0pOwogICAgICAgIH0KICAgICAgICBpZih0ID09IDMpCiAgICAgICAgewogICAgICAgICAgICBpbnQgYSwgYjsKICAgICAgICAgICAgY2luID4+IGEgPj4gYjsKICAgICAgICAgICAgYXV0byBpdDEgPSAtLW1lLnVwcGVyX2JvdW5kKGEpOwogICAgICAgICAgICBhdXRvIGl0MiA9IC0tbWUudXBwZXJfYm91bmQoYik7CiAgICAgICAgICAgIGlmKGl0MS0+c2Vjb25kID09IGl0Mi0+c2Vjb25kKQogICAgICAgICAgICAgICAgY291dCA8PCAiWUVTXG4iOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBjb3V0IDw8ICJOT1xuIjsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQ==