// rbtree (https://rbtr.ee) #include "bits/stdc++.h" int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) { return 0; } struct SNOWFLAKE { static constexpr char __FIO__[] = ""; static constexpr char __FIN__[] = ""; static constexpr char __FOUT__[] = ""; static constexpr bool MTS = false; static constexpr bool SPC_MTS = false; template using vla = std::vector; template using pair = std::pair; using string = std::string; using ll = long long int; using ull = unsigned long long int; using vb = vla; using vi = vla; using vl = vla; using pii = std::pair; using pil = std::pair; using pli = std::pair; using pll = std::pair; static constexpr int INF32 = 0x3ffffffe; static constexpr ll INF64 = 0x3ffffffffffffffe; template void ckmin(Ty1& x, Ty2 y) { if (y < x) x = y; } template void ckmax(Ty1& x, Ty2 y) { if (x < y) x = y; } void ccin() {} template void ccin(Ty1& x, Ty2&... y) { std::cin >> x; ccin(y...); } #define ccin(Ty, ...) Ty __VA_ARGS__; ccin(__VA_ARGS__) struct Constructor { Constructor() { if (strlen(__FIO__) != 0) { freopen((std::string(__FIO__) + ".in").c_str(), "r", stdin); freopen((std::string(__FIO__) + ".out").c_str(), "w", stdout); } else { if (strlen(__FIN__) != 0) freopen(__FIN__, "r", stdin); if (strlen(__FOUT__) != 0) freopen(__FOUT__, "w", stdout); } std::cin.tie(nullptr)->sync_with_stdio(false); } } Constructor; SNOWFLAKE() { int t = 1; if (MTS && !SPC_MTS) std::cin >> t; for (int i = 1; i <= t || SPC_MTS; ++i) { if (TRANSMIGRATION(i) != 0) return; } } using Sts = struct { ll a1; ll f1; ll a2; ll f2; }; Sts sab(Sts o, int s) { return { o.a2, o.f2 - 1, o.a1 + s, o.f1 }; } Sts att(Sts o) { return { o.a2 - o.a1, o.f2, o.a1, o.f1 }; } ll dp(ll f1, ll f2, ll b2, int s, auto& f) { if (f[f2][f1][b2] != -1) return f[f2][f1][b2]; int l = 1; int r = s - 1; while (l <= r) { int mid = (l + r) / 2; Sts o = { mid, f1, s - b2, f2 }; if (!win(sab(o, s), s, f) || !win(att(o), s, f)) { r = mid - 1; f[f2][f1][b2] = mid; } else l = mid + 1; } return f[f2][f1][b2]; } bool win(Sts o, int s, auto& f) { auto [a1, f1, a2, f2] = o; if (a1 + s * f2 <= 0) return false; if (a2 + s * f1 <= 0) return true; if (a1 <= 0 && a2 <= 0) { ll rnd = std::max(0ll, -std::max(a1, a2) / s + 1); f1 -= rnd, f2 -= rnd; a1 += rnd * s, a2 += rnd * s; o = { a1, f1, a2, f2 }; } if (a1 <= 0 && f1 == 0 && a2 < s) { ll rnd = -a1 / (s - a2) + 1; f2 -= rnd; a1 += rnd * (s - a2); if (f2 < 0 || a1 + s * f2 <= 0) return false; o = { a1, f1, a2, f2 }; } if (a1 <= 0) return !win(sab(o, s), s, f); if (a1 >= s && a2 <= s) return true; if (a2 >= s) return !win(att(o), s, f); ll b1 = s - a1; ll b2 = std::min((ll)s, s - a2); if (f2 >= s) return true; if (a1 + b2 * f2 >= s) return true; if (b1 * f1 >= a1 + b2) { ll rnd = std::min(f2, ((s * f1 - b2) / (f1 + 1) - a1) / b2 + 1); f2 -= rnd; a1 += rnd * b2; o = { a1, f1, a2, f2 }; } if (f2 == 0) return !win(att(o), s, f); if ((f1 + 1) * b2 * f2 * f2 > 8 * s) return true; return dp(f1, f2, b2, s, f) <= a1; } int TRANSMIGRATION([[maybe_unused]] int TEST_NUMBER) { ccin(int, s, q); vla> f(std::sqrt(8 * s) + 1); for (int f2 = 1; f2 * f2 <= 8 * s; ++f2) { for (int f1 = 0; f1 * f2 * f2 <= 8 * s; ++f1) { int b2 = 0; while ((f1 + 1) * f2 * f2 * b2 <= 8 * s) ++b2; f[f2].emplace_back(b2, -1); } } for (int i = 0; i < q; ++i) { ccin(ll, c1, f1, c2, f2); bool w = win({ c1 - s * f2, f1, c2 - s * f1, f2 }, s, f); std::cout << (w ? "YES\n" : "NO\n"); } return 0; } #undef ccin } SNOWFLAKE;