#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
vector<int> sq;
const int maxN = 300000;
int nxt[maxN];
int sz[maxN];
int leader(int a) {
  if (a == nxt[a]) {
    return a;
  } else {
    int pp = leader(nxt[a]);
    nxt[a] = pp;
    return pp;
  }
}
bool in(int a, int b) { return (leader(a) == leader(b)); }
void unite(int a, int b) {
  int a1 = leader(a);
  int b1 = leader(b);
  if (a1 == b1) {
    return;
  }
  if (sz[a1] > sz[b1]) {
    nxt[b1] = a1;
    sz[a1] += sz[b1];
    sz[b1] = 0;
  } else {
    nxt[a1] = b1;
    sz[b1] += sz[a1];
    sz[a1] = 0;
  }
}
int num[maxN];
int main() {
  int n, q;
  cin >> n >> q;
  int pp = sqrt(1.0 * n) + 1;
  int cnt = 0;
  int l = 0;
  int tmp = 0;
  for (int i = 1; i <= n; i++) {
    nxt[i] = i;
    sz[i] = 1;
    num[i] = tmp;
    if (cnt == 0) {
      l = i;
    }
    cnt++;
    if (cnt == pp || i == n) {
      v.push_back(make_pair(l, i));
      cnt = 0;
      l = 0;
      sq.push_back(0);
      tmp++;
    }
  }
  ios_base::sync_with_stdio(0);
  int tx = 0;
  int ty = 0;
  for (int i = 1; i <= q; i++) {
    int tp, x, y;
    scanf("%d %d %d", &tp, &x, &y);
    if (tp == 3) {
      puts((leader(x) == leader(y)) ? "YES" : "NO");
      puts("\n");
    }
    if (tp == 1) {
      unite(x, y);
    }
    if (tp == 2) {
      if (tx == x && ty == y) {
        continue;
      }
      tx = x;
      ty = y;
      if (sq[num[x]] == 0) {
        for (int j = x; j <= min(y, v[num[x]].second); j++) {
          unite(x, j);
        }
      }
      if (sq[num[y]] == 0) {
        for (int j = max(x, v[num[y]].first); j <= y; j++) {
          unite(x, j);
        }
      }
      for (int j = num[x] + 1; j <= num[y] - 1; j++) {
        if (sq[j] == 0) {
          for (int pp = v[j].first; pp <= v[j].second; pp++) {
            unite(x, pp);
          }
          sq[j] = 1;
        } else {
          unite(x, v[j].first);
        }
      }
    }
  }
  return 0;
}
