Skip to content

Commit 6d8da5e

Browse files
committed
add/fix tests
1 parent a716e16 commit 6d8da5e

File tree

5 files changed

+55
-13
lines changed

5 files changed

+55
-13
lines changed

geometry/sort_by_argument.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
#pragma once
2-
#include <cmath>
32

4-
// CUT begin
53
// Point on grid, sortable by its argument
64
struct Point {
7-
constexpr static double eps = 1e-2;
85
long long X, Y;
9-
double theta;
106
Point() = default;
11-
Point(long long x, long long y) : X(x), Y(y), theta(std::atan2(y, x)) {}
7+
Point(long long x, long long y) : X(x), Y(y) {}
8+
129
bool operator<(const Point &r) const {
13-
double b = theta - r.theta;
14-
return std::abs(b) > eps ? (b < 0) : (X * r.Y > r.X * Y);
10+
const int ll = lower_or_upper(), lr = r.lower_or_upper();
11+
if (ll != lr) return ll < lr;
12+
return X * r.Y > r.X * Y;
1513
}
14+
1615
bool operator==(const Point &r) const {
17-
return std::abs(theta - r.theta) < eps and X * r.Y == r.X * Y;
16+
return lower_or_upper() == r.lower_or_upper() and X * r.Y == r.X * Y;
1817
}
19-
void rotate_pi() {
20-
theta += M_PI;
21-
X *= -1;
22-
Y *= -1;
18+
19+
int lower_or_upper() const {
20+
if (Y) return Y > 0 ? 1 : -1;
21+
if (X) return X > 0 ? -1 : 1;
22+
return 0; // origin
2323
}
24+
25+
void rotate_pi() { X = -X, Y = -Y; }
2426
};

geometry/test/sort_by_argument.test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
#define PROBLEM "https://judge.yosupo.jp/problem/sort_points_by_argument"
12
#include "geometry/sort_by_argument.hpp"
3+
24
#include <algorithm>
35
#include <iostream>
46
#include <vector>
5-
#define PROBLEM "https://judge.yosupo.jp/problem/sort_points_by_argument"
67
using namespace std;
78

89
int main() {

random/rand_nondeterministic.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
struct rand_int_ {
66
using lint = long long;
77
std::mt19937 mt;
8+
// rand_int_() : mt(42) {}
89
rand_int_() : mt(std::chrono::steady_clock::now().time_since_epoch().count()) {}
910
lint operator()(lint x) { return this->operator()(0, x); } // [0, x)
1011
lint operator()(lint l, lint r) {
File renamed without changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#define PROBLEM "https://judge.yosupo.jp/problem/unionfind_with_potential"
2+
3+
#include "../potentialized_unionfind.hpp"
4+
5+
#include <iostream>
6+
using namespace std;
7+
8+
#include <atcoder/modint>
9+
using mint = atcoder::modint998244353;
10+
11+
int main() {
12+
cin.tie(nullptr), ios::sync_with_stdio(false);
13+
14+
int N, Q;
15+
cin >> N >> Q;
16+
PotentializedUnionFind<mint> uf(N);
17+
18+
while (Q--) {
19+
int t, u, v;
20+
cin >> t >> u >> v;
21+
if (t == 0) {
22+
int x;
23+
cin >> x;
24+
if (uf.same(u, v) and uf.diff(v, u) != x) {
25+
cout << "0\n";
26+
} else {
27+
cout << "1\n";
28+
uf.unite(v, u, x);
29+
}
30+
} else {
31+
if (uf.same(u, v)) {
32+
cout << uf.diff(v, u).val() << '\n';
33+
} else {
34+
cout << "-1\n";
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)