diff options
| author | MZuenni <michi.zuendorf@gmail.com> | 2023-03-01 16:56:27 +0100 |
|---|---|---|
| committer | MZuenni <michi.zuendorf@gmail.com> | 2023-03-01 16:56:27 +0100 |
| commit | b15088d04aac27a3ef94cf79e68d681d735b1bbc (patch) | |
| tree | 96ba00e474790acd62d10a5d1ae5699e42cf6b4c /datastructures | |
| parent | d8eefacaebee4e08aa92ae507d49079d90a93580 (diff) | |
reformatted empty lines
Diffstat (limited to 'datastructures')
| -rw-r--r-- | datastructures/LCT.cpp | 30 | ||||
| -rw-r--r-- | datastructures/unionFind2.cpp | 4 |
2 files changed, 17 insertions, 17 deletions
diff --git a/datastructures/LCT.cpp b/datastructures/LCT.cpp index b67ab82..9adae89 100644 --- a/datastructures/LCT.cpp +++ b/datastructures/LCT.cpp @@ -34,17 +34,17 @@ struct LCT { bool revert; int id, size; Node *left, *right, *parent; - + Node(int id = 0, int val = queryDefault) : nodeValue(val), subTreeValue(val), delta(updateDefault), revert(false), id(id), size(1), left(nullptr), right(nullptr), parent(nullptr) {} - + bool isRoot() { return !parent || (parent->left != this && parent->right != this); } - + void push() { if (revert) { revert = false; @@ -63,7 +63,7 @@ struct LCT { ll getSubtreeValue() { return joinValueDelta(subTreeValue, _update(delta, size)); } - + void update() { subTreeValue = joinValueDelta(nodeValue, delta); size = 1; @@ -78,13 +78,13 @@ struct LCT { size += right->size; }} }; - + vector<Node> nodes; - + LCT(int n) : nodes(n) { for (int i = 0; i < n; i++) nodes[i].id = i; } - + void connect(Node* ch, Node* p, int isLeftChild) { if (ch) ch->parent = p; if (isLeftChild >= 0) { @@ -103,7 +103,7 @@ struct LCT { connect(x, g, isRootP ? -1 : p == g->left); p->update(); } - + void splay(Node* x) { while (!x->isRoot()) { Node* p = x->parent; @@ -118,7 +118,7 @@ struct LCT { x->push(); x->update(); } - + Node* expose(Node* x) { Node* last = nullptr; for (Node* y = x; y; y = y->parent) { @@ -129,25 +129,25 @@ struct LCT { splay(x); return last; } - + void makeRoot(Node* x) { expose(x); x->revert ^= 1; } - + bool connected(Node* x, Node* y) { if (x == y) return true; expose(x); expose(y); return x->parent; } - + void link(Node* x, Node* y) { assert(!connected(x, y)); // not yet connected! makeRoot(x); x->parent = y; } - + void cut(Node* x, Node* y) { makeRoot(x); expose(y); @@ -162,14 +162,14 @@ struct LCT { expose(x); return expose(y); } - + ll query(Node* from, Node* to) { makeRoot(from); expose(to); if (to) return to->getSubtreeValue(); return queryDefault; } - + void modify(Node* from, Node* to, ll delta) { makeRoot(from); expose(to); diff --git a/datastructures/unionFind2.cpp b/datastructures/unionFind2.cpp index b86c8e0..5362c4d 100644 --- a/datastructures/unionFind2.cpp +++ b/datastructures/unionFind2.cpp @@ -9,7 +9,7 @@ int findSet(int i) { uf[i] = findSet(uf[i]); //Path-Compression return uf[i]; } - + void linkSets(int i, int j) { //Take |uf[i]|, where i must be a root, to get the size //of the subset @@ -19,7 +19,7 @@ void linkSets(int i, int j) { uf[i] += uf[j]; uf[j] = i; } } - + void unionSets(int i, int j) { if(findSet(i) != findSet(j)) linkSets(findSet(i),findSet(j)); } |
