From e55df069a8f83b2c0c2b56c035f49e89516cdaaa Mon Sep 17 00:00:00 2001 From: Gloria Mundi Date: Sat, 16 Nov 2024 17:48:10 +0100 Subject: minor fixes, let code breathe where possible --- content/datastructures/dynamicConvexHull.cpp | 8 ++--- content/datastructures/lichao.cpp | 14 ++++---- content/datastructures/persistentArray.cpp | 48 ++++++++++++++-------------- 3 files changed, 35 insertions(+), 35 deletions(-) (limited to 'content/datastructures') 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> { // 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 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 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 -struct persistentArray { - int time; - vector> data; - vector> 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 +struct persistentArray { + int time; + vector> data; + vector> 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; + } +}; -- cgit v1.2.3