From 0f1223c5396961a661da4f12caf0252f924de01b Mon Sep 17 00:00:00 2001 From: Gloria Mundi Date: Wed, 19 Feb 2025 21:29:03 +0100 Subject: reverse dynamic convex hull --- content/datastructures/dynamicConvexHull.cpp | 6 +++--- test/datastructures/dynamicConvexHull.cpp | 4 ++-- test/datastructures/dynamicConvexHull.lichao.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/content/datastructures/dynamicConvexHull.cpp b/content/datastructures/dynamicConvexHull.cpp index 36ef6f5..3e4020e 100644 --- a/content/datastructures/dynamicConvexHull.cpp +++ b/content/datastructures/dynamicConvexHull.cpp @@ -1,16 +1,16 @@ struct Line { mutable ll m, c, p; - bool operator<(const Line& o) const { return m < o.m; } + bool operator<(const Line& o) const { return m > o.m; } bool operator<(ll x) const { return p < x; } }; -struct HullDynamic : multiset> { // max über Geraden +struct HullDynamic : multiset> { // min über Geraden // (for doubles, use INF = 1/.0, div(a,c) = a/c) ll div(ll a, ll c) { return a / c - ((a ^ c) < 0 && a % c); } bool isect(iterator x, iterator y) { if (y == end()) { x->p = INF; return false; } - if (x->m == y->m) x->p = x->c > y->c ? INF : -INF; + if (x->m == y->m) x->p = x->c < y->c ? INF : -INF; else x->p = div(y->c - x->c, x->m - y->m); return x->p >= y->p; } diff --git a/test/datastructures/dynamicConvexHull.cpp b/test/datastructures/dynamicConvexHull.cpp index e0345af..02e50f4 100644 --- a/test/datastructures/dynamicConvexHull.cpp +++ b/test/datastructures/dynamicConvexHull.cpp @@ -29,7 +29,7 @@ void stress_test(ll range) { ll got = hd.query(x); ll expected = naive[0](x); - for (auto l : naive) expected = max(expected, l(x)); + for (auto l : naive) expected = min(expected, l(x)); if (got != expected) cerr << "got: " << got << ", expected: " << expected << FAIL; queries++; @@ -49,7 +49,7 @@ void performance_test() { ll m = Random::integer(-1'000'000'000, 1'000'000'000); ll c = Random::integer(-1'000'000'000, 1'000'000'000); ll x = Random::integer(-1'000'000'000, 1'000'000'000); - + t.start(); hd.add(m, c); hash += hd.query(x); diff --git a/test/datastructures/dynamicConvexHull.lichao.cpp b/test/datastructures/dynamicConvexHull.lichao.cpp index 9a6ffb9..f692e92 100644 --- a/test/datastructures/dynamicConvexHull.lichao.cpp +++ b/test/datastructures/dynamicConvexHull.lichao.cpp @@ -16,11 +16,11 @@ void stress_test(ll range) { ll m = Random::integer(-range, range); ll c = Random::integer(-range, range); hd.add(m, c); - lichao.insert({-m, -c}); + lichao.insert({m, c}); for (ll x : xs) { ll gotA = hd.query(x); - ll gotB = -lichao.query(x); + ll gotB = lichao.query(x); if (gotA != gotB) cerr << "gotA: " << gotA << ", gotB: " << gotB << FAIL; queries++; -- cgit v1.2.3