Skip to content

Commit

Permalink
Shorter LineContainer
Browse files Browse the repository at this point in the history
(thanks, dacin21!)
  • Loading branch information
simonlindholm committed Dec 19, 2018
1 parent 7152840 commit 165807e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions content/data-structures/LineContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
*/
#pragma once

bool Q;
struct Line {
mutable ll k, m, p;
bool operator<(const Line& o) const {
return Q ? p < o.p : k < o.k;
}
bool operator<(const Line& o) const { return k < o.k; }
bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line> {
struct LineContainer : multiset<Line, less<>> {
// (for doubles, use inf = 1/.0, div(a,b) = a/b)
const ll inf = LLONG_MAX;
ll div(ll a, ll b) { // floored division
Expand All @@ -38,7 +36,7 @@ struct LineContainer : multiset<Line> {
}
ll query(ll x) {
assert(!empty());
Q = 1; auto l = *lower_bound({0,0,x}); Q = 0;
auto l = *lower_bound(x);
return l.k * x + l.m;
}
};

0 comments on commit 165807e

Please sign in to comment.