summaryrefslogtreecommitdiff
path: root/content/datastructures
diff options
context:
space:
mode:
Diffstat (limited to 'content/datastructures')
-rw-r--r--content/datastructures/dynamicConvexHull.cpp8
-rw-r--r--content/datastructures/lichao.cpp14
-rw-r--r--content/datastructures/persistentArray.cpp48
3 files changed, 35 insertions, 35 deletions
diff --git a/content/datastructures/dynamicConvexHull.cpp b/content/datastructures/dynamicConvexHull.cpp
index 7148e31..36ef6f5 100644
--- a/content/datastructures/dynamicConvexHull.cpp
+++ b/content/datastructures/dynamicConvexHull.cpp
@@ -1,15 +1,15 @@
struct Line {
mutable ll m, c, p;
- bool operator<(const Line& o) const {return m < o.m;}
- bool operator<(ll x) const {return p < x;}
+ bool operator<(const Line& o) const { return m < o.m; }
+ bool operator<(ll x) const { return p < x; }
};
struct HullDynamic : multiset<Line, less<>> { // max ü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);}
+ 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 (y == end()) { x->p = INF; return false; }
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/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)); }
};
diff --git a/content/datastructures/persistentArray.cpp b/content/datastructures/persistentArray.cpp
index 8326700..903bd0e 100644
--- a/content/datastructures/persistentArray.cpp
+++ b/content/datastructures/persistentArray.cpp
@@ -1,24 +1,24 @@
-template<typename T>
-struct persistentArray {
- int time;
- vector<persistent<T>> data;
- vector<pair<int, int>> mods;
-
- persistentArray(int n, T value = {})
- : time(0), data(n, {time, value}) {}
-
- T get(int p, int t) {return data[p].get(t);}
-
- int set(int p, T value) {
- mods.push_back({p, data[p].set(value)});
- return mods.back().second;
- }
-
- void reset(int t) {
- while (!mods.empty() && mods.back().second > t) {
- data[mods.back().first].data.pop_back();
- mods.pop_back();
- }
- time = t;
- }
-};
+template<typename T>
+struct persistentArray {
+ int time;
+ vector<persistent<T>> data;
+ vector<pair<int, int>> mods;
+
+ persistentArray(int n, T value = {})
+ : time(0), data(n, {time, value}) {}
+
+ T get(int p, int t) { return data[p].get(t); }
+
+ int set(int p, T value) {
+ mods.push_back({p, data[p].set(value)});
+ return mods.back().second;
+ }
+
+ void reset(int t) {
+ while (!mods.empty() && mods.back().second > t) {
+ data[mods.back().first].data.pop_back();
+ mods.pop_back();
+ }
+ time = t;
+ }
+};