summaryrefslogtreecommitdiff
path: root/content/datastructures/lichao.cpp
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 17:48:10 +0100
committerGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 18:01:53 +0100
commite55df069a8f83b2c0c2b56c035f49e89516cdaaa (patch)
treedd6767e3fc6ac8532661dc75886a3056804d1d46 /content/datastructures/lichao.cpp
parent72bd993483453ed8ebc462f1a33385cd355d486f (diff)
minor fixes, let code breathe where possible
Diffstat (limited to 'content/datastructures/lichao.cpp')
-rw-r--r--content/datastructures/lichao.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/content/datastructures/lichao.cpp b/content/datastructures/lichao.cpp
index 1318ca7..c20c61d 100644
--- a/content/datastructures/lichao.cpp
+++ b/content/datastructures/lichao.cpp
@@ -1,9 +1,9 @@
vector<ll> xs; // IMPORTANT: Initialize before constructing!
-int findX(int i) {return lower_bound(all(xs), i) - begin(xs);}
+int findX(int i) { return lower_bound(all(xs), i) - begin(xs); }
-struct Fun { // Default: Linear function. Change as needed.
+struct Fun { // Default: Linear function. Change as needed.
ll m, c;
- ll operator()(int x) {return m*xs[x] + c;}
+ ll operator()(int x) { return m*xs[x] + c; }
};
// Default: Computes min. Change lines with comment for max.
@@ -12,17 +12,17 @@ struct Lichao {
int n, cap;
vector<Fun> seg;
Lichao() : n(sz(xs)), cap(2 << __lg(n)), seg(2 * cap, id) {}
-
+
void _insert(Fun f, int l, int r, int i) {
while (i < 2 * cap) {
int m = (l+r)/2;
- if (m >= n) {r = m; i = 2*i; continue;}
+ if (m >= n) { r = m; i = 2*i; continue; }
Fun &g = seg[i];
if (f(m) < g(m)) swap(f, g); // >
if (f(l) < g(l)) r = m, i = 2*i; // >
else l = m, i = 2*i+1;
}}
- void insert(Fun f) {_insert(f, 0, cap, 1);}
+ void insert(Fun f) { _insert(f, 0, cap, 1); }
void _segmentInsert(Fun f, int l, int r, int a, int b, int i) {
if (l <= a && b <= r) _insert(f, a, b, i);
@@ -42,5 +42,5 @@ struct Lichao {
}
return ans;
}
- ll query(ll x) {return _query(findX(x));}
+ ll query(ll x) { return _query(findX(x)); }
};