diff options
Diffstat (limited to 'content/datastructures/lichao.cpp')
| -rw-r--r-- | content/datastructures/lichao.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/content/datastructures/lichao.cpp b/content/datastructures/lichao.cpp index 9c41934..da965dd 100644 --- a/content/datastructures/lichao.cpp +++ b/content/datastructures/lichao.cpp @@ -1,9 +1,10 @@ vector<ll> xs; // IMPORTANT: Initialize before constructing! -int findX(ll i) {return lower_bound(all(xs), i) - begin(xs);} +int findX(ll i) { + return ranges::lower_bound(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. @@ -11,18 +12,18 @@ struct Lichao { static constexpr Fun id = {0, INF}; // {0, -INF} int n, cap; vector<Fun> seg; - Lichao() : n(sz(xs)), cap(2 << __lg(n)), seg(2 * cap, id) {} - + Lichao() : n(ssize(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 +43,5 @@ struct Lichao { } return ans; } - ll query(ll x) {return _query(findX(x));} + ll query(ll x) { return _query(findX(x)); } }; |
