From 6d8da5e685eed508585312dada5857ca9f96da2c Mon Sep 17 00:00:00 2001 From: hitonanode <32937551+hitonanode@users.noreply.github.com> Date: Tue, 5 Aug 2025 22:50:49 +0900 Subject: [PATCH] add/fix tests --- geometry/sort_by_argument.hpp | 26 +++++++------ geometry/test/sort_by_argument.test.cpp | 3 +- random/rand_nondeterministic.hpp | 1 + ...entialized_unionfind.aoj_dsl_1_b.test.cpp} | 0 .../potentialized_unionfind_modint.test.cpp | 38 +++++++++++++++++++ 5 files changed, 55 insertions(+), 13 deletions(-) rename unionfind/test/{potentialized_unionfind.test.cpp => potentialized_unionfind.aoj_dsl_1_b.test.cpp} (100%) create mode 100644 unionfind/test/potentialized_unionfind_modint.test.cpp diff --git a/geometry/sort_by_argument.hpp b/geometry/sort_by_argument.hpp index b2904414..256b885f 100644 --- a/geometry/sort_by_argument.hpp +++ b/geometry/sort_by_argument.hpp @@ -1,24 +1,26 @@ #pragma once -#include -// CUT begin // Point on grid, sortable by its argument struct Point { - constexpr static double eps = 1e-2; long long X, Y; - double theta; Point() = default; - Point(long long x, long long y) : X(x), Y(y), theta(std::atan2(y, x)) {} + Point(long long x, long long y) : X(x), Y(y) {} + bool operator<(const Point &r) const { - double b = theta - r.theta; - return std::abs(b) > eps ? (b < 0) : (X * r.Y > r.X * Y); + const int ll = lower_or_upper(), lr = r.lower_or_upper(); + if (ll != lr) return ll < lr; + return X * r.Y > r.X * Y; } + bool operator==(const Point &r) const { - return std::abs(theta - r.theta) < eps and X * r.Y == r.X * Y; + return lower_or_upper() == r.lower_or_upper() and X * r.Y == r.X * Y; } - void rotate_pi() { - theta += M_PI; - X *= -1; - Y *= -1; + + int lower_or_upper() const { + if (Y) return Y > 0 ? 1 : -1; + if (X) return X > 0 ? -1 : 1; + return 0; // origin } + + void rotate_pi() { X = -X, Y = -Y; } }; diff --git a/geometry/test/sort_by_argument.test.cpp b/geometry/test/sort_by_argument.test.cpp index 1fa1b2a0..d3ad9ae7 100644 --- a/geometry/test/sort_by_argument.test.cpp +++ b/geometry/test/sort_by_argument.test.cpp @@ -1,8 +1,9 @@ +#define PROBLEM "https://judge.yosupo.jp/problem/sort_points_by_argument" #include "geometry/sort_by_argument.hpp" + #include #include #include -#define PROBLEM "https://judge.yosupo.jp/problem/sort_points_by_argument" using namespace std; int main() { diff --git a/random/rand_nondeterministic.hpp b/random/rand_nondeterministic.hpp index 227d4ec4..3805126c 100644 --- a/random/rand_nondeterministic.hpp +++ b/random/rand_nondeterministic.hpp @@ -5,6 +5,7 @@ struct rand_int_ { using lint = long long; std::mt19937 mt; + // rand_int_() : mt(42) {} rand_int_() : mt(std::chrono::steady_clock::now().time_since_epoch().count()) {} lint operator()(lint x) { return this->operator()(0, x); } // [0, x) lint operator()(lint l, lint r) { diff --git a/unionfind/test/potentialized_unionfind.test.cpp b/unionfind/test/potentialized_unionfind.aoj_dsl_1_b.test.cpp similarity index 100% rename from unionfind/test/potentialized_unionfind.test.cpp rename to unionfind/test/potentialized_unionfind.aoj_dsl_1_b.test.cpp diff --git a/unionfind/test/potentialized_unionfind_modint.test.cpp b/unionfind/test/potentialized_unionfind_modint.test.cpp new file mode 100644 index 00000000..367b666b --- /dev/null +++ b/unionfind/test/potentialized_unionfind_modint.test.cpp @@ -0,0 +1,38 @@ +#define PROBLEM "https://judge.yosupo.jp/problem/unionfind_with_potential" + +#include "../potentialized_unionfind.hpp" + +#include +using namespace std; + +#include +using mint = atcoder::modint998244353; + +int main() { + cin.tie(nullptr), ios::sync_with_stdio(false); + + int N, Q; + cin >> N >> Q; + PotentializedUnionFind uf(N); + + while (Q--) { + int t, u, v; + cin >> t >> u >> v; + if (t == 0) { + int x; + cin >> x; + if (uf.same(u, v) and uf.diff(v, u) != x) { + cout << "0\n"; + } else { + cout << "1\n"; + uf.unite(v, u, x); + } + } else { + if (uf.same(u, v)) { + cout << uf.diff(v, u).val() << '\n'; + } else { + cout << "-1\n"; + } + } + } +}