#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1000000000;
const long long inf_ll = 100000000000000000;
const long double pi = 3.1415926535898;
template <typename T>
void prin(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i] << " ";
  }
}
template <typename T>
void prin_new_line(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i] << "\n";
  }
}
int sum_vec(vector<int>& a) {
  int s = 0;
  for (int i = 0; i < a.size(); i++) {
    s += a[i];
  }
  return s;
}
template <typename T>
T max(vector<T>& a) {
  T ans = a[0];
  for (int i = 1; i < a.size(); i++) {
    ans = max(ans, a[i]);
  }
  return ans;
}
template <typename T>
T min(vector<T>& a) {
  T ans = a[0];
  for (int i = 1; i < a.size(); i++) {
    ans = min(ans, a[i]);
  }
  return ans;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  gcd(b, a % b);
}
int min(int a, int b, int c) { return min(a, min(b, c)); }
long long min(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
int max(int a, int b, int c) { return max(a, max(b, c)); }
long long max(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
vector<int> a;
vector<int> Parent(200005);
vector<int> Rank(200005);
void make_set(int v) {
  Parent[v] = v;
  Rank[v] = 0;
}
int find_parent(int v) {
  if (v == Parent[v]) return v;
  return Parent[v] = find_parent(Parent[v]);
}
void union_set(int a, int b) {
  a = find_parent(a);
  b = find_parent(b);
  if (a != b) {
    if (Rank[a] < Rank[b]) swap(a, b);
    Parent[b] = a;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int q;
  cin >> q;
  set<pair<int, int> > a;
  for (int i = 1; i <= n; i++) {
    make_set(i);
    a.insert({i, i});
  }
  for (int j = 0; j < q; j++) {
    int x, y;
    cin >> x;
    if (x == 3) {
      cin >> x >> y;
      if (find_parent(x) == find_parent(y)) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    } else if (x == 1) {
      cin >> x >> y;
      union_set(x, y);
    } else {
      int x, y;
      cin >> x >> y;
      set<pair<int, int> >::iterator it1 = a.upper_bound({x, inf_int});
      set<pair<int, int> >::iterator it3 = it1;
      it1--;
      int y1;
      set<pair<int, int> >::iterator it2 = a.upper_bound({y, inf_int});
      it2--;
      y1 = it2->second;
      it2++;
      x = (it1->first);
      for (; it1 != it2; it1++) {
        union_set(x, it1->first);
      }
      it1--;
      it3--;
      a.erase(it3, it2);
      a.insert({x, y1});
    }
  }
}
