Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions geometry/sort_by_argument.hpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#pragma once
#include <cmath>

// 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; }
};
3 changes: 2 additions & 1 deletion geometry/test/sort_by_argument.test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#define PROBLEM "https://judge.yosupo.jp/problem/sort_points_by_argument"
#include "geometry/sort_by_argument.hpp"

#include <algorithm>
#include <iostream>
#include <vector>
#define PROBLEM "https://judge.yosupo.jp/problem/sort_points_by_argument"
using namespace std;

int main() {
Expand Down
1 change: 1 addition & 0 deletions random/rand_nondeterministic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 38 additions & 0 deletions unionfind/test/potentialized_unionfind_modint.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#define PROBLEM "https://judge.yosupo.jp/problem/unionfind_with_potential"

#include "../potentialized_unionfind.hpp"

#include <iostream>
using namespace std;

#include <atcoder/modint>
using mint = atcoder::modint998244353;

int main() {
cin.tie(nullptr), ios::sync_with_stdio(false);

int N, Q;
cin >> N >> Q;
PotentializedUnionFind<mint> 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";
}
}
}
}