Skip to content

Commit

Permalink
Chore: build snippet, index, site
Browse files Browse the repository at this point in the history
  • Loading branch information
theSoberSobber committed Apr 20, 2024
1 parent 809d113 commit 2dba8c6
Show file tree
Hide file tree
Showing 15 changed files with 414 additions and 16 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ curl -L "https://raw.githubusercontent.com/theSoberSobber/CP-Snippets/main/snipp
- **[rr-segtree](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2190)** : best segtree
- **[segtree](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2334)** : sextree
- **[seive](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2448)** : seive
- **[tokenizer](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2466)** : tokenizer that has no use
- **[totient-seive](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2473)** : totient-seive
- **[totient](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2487)** : totient
- **[trie](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2507)** : trie
- **[troll](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2543)** : troll
- **[two-sat (kosaraju)](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2553)** : two-sat (kosaraju)
- **[variadic](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2690)** : variadic lambdas with 1 and 2 arguments
- **[xor-basis](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2699)** : xor-basis
- **[splay-tree-rr-sir](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2466)** : used here by rr sir, I have no idea how to use it or what it's used in mostly, [RR Sir ABC F Submission](https://atcoder.jp/contests/abc350/submissions/52600529)
- **[tokenizer](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2661)** : tokenizer that has no use
- **[totient-seive](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2668)** : totient-seive
- **[totient](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2682)** : totient
- **[trie](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2702)** : trie
- **[troll](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2738)** : troll
- **[two-sat (kosaraju)](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2748)** : two-sat (kosaraju)
- **[variadic](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2885)** : variadic lambdas with 1 and 2 arguments
- **[xor-basis](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2894)** : xor-basis
Binary file modified book/codebook-dark.pdf
Binary file not shown.
Binary file modified book/codebook-light.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ curl -L "https://raw.githubusercontent.com/theSoberSobber/CP-Snippets/main/snipp
- **[rr-segtree](https://thesobersobber.github.io/CP-Snippets/rr-segtree)** : best segtree
- **[segtree](https://thesobersobber.github.io/CP-Snippets/segtree)** : sextree
- **[seive](https://thesobersobber.github.io/CP-Snippets/seive)** : seive
- **[splay-tree-rr-sir](https://thesobersobber.github.io/CP-Snippets/Splay Tree)** : used here by rr sir, I have no idea how to use it or what it's used in mostly, [RR Sir ABC F Submission](https://atcoder.jp/contests/abc350/submissions/52600529)
- **[tokenizer](https://thesobersobber.github.io/CP-Snippets/tokenizer)** : tokenizer that has no use
- **[totient-seive](https://thesobersobber.github.io/CP-Snippets/totient-seive)** : totient-seive
- **[totient](https://thesobersobber.github.io/CP-Snippets/totient)** : totient
Expand Down
200 changes: 200 additions & 0 deletions docs/Splay Tree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@

## splay-tree-rr-sir

- used here by rr sir, I have no idea how to use it or what it's used in mostly, [RR Sir ABC F Submission](https://atcoder.jp/contests/abc350/submissions/52600529)
- ```
https://thesobersobber.github.io/CP-Snippets/Splay Tree
```
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2466)

```cpp

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

namespace allocator {

// Array allocator.
template <class T, int MAXSIZE>
struct array {
T v[MAXSIZE], *top;
array() : top(v) {}
T *alloc(const T &val = T()) { return &(*top++ = val); }
void dealloc(T *p) {}
};

// Stack-based array allocator.
template <class T, int MAXSIZE>
struct stack {
T v[MAXSIZE];
T *spot[MAXSIZE], **top;
stack() {
for (int i = 0; i < MAXSIZE; ++i) spot[i] = v + i;
top = spot + MAXSIZE;
}
T *alloc(const T &val = T()) { return &(**--top = val); }
void dealloc(T *p) { *top++ = p; }
};

} // namespace allocator

namespace splay {

// Abstract node struct.
template <class T>
struct node {
T *f, *c[2];
int size;
node() {
f = c[0] = c[1] = nullptr;
size = 1;
}
void push_down() {}
void update() {
size = 1;
for (int t = 0; t < 2; ++t)
if (c[t]) size += c[t]->size;
}
};

// Abstract reversible node struct.
template <class T>
struct reversible_node : node<T> {
int r;
reversible_node() : node<T>() { r = 0; }
void push_down() {
node<T>::push_down();
if (r) {
for (int t = 0; t < 2; ++t)
if (node<T>::c[t]) node<T>::c[t]->reverse();
r = 0;
}
}
void update() { node<T>::update(); }
// Reverse the range of this node.
void reverse() {
std::swap(node<T>::c[0], node<T>::c[1]);
r = r ^ 1;
}
};

template <class T, int MAXSIZE = 500000,
class alloc = allocator::array<T, MAXSIZE + 2>>
struct tree {
alloc pool;
T *root;
// Get a new node from the pool.
T *new_node(const T &val = T()) { return pool.alloc(val); }
tree() {
root = new_node(), root->c[1] = new_node(), root->size = 2;
root->c[1]->f = root;
}
// Helper function to rotate node.
void rotate(T *n) {
int v = n->f->c[0] == n;
T *p = n->f, *m = n->c[v];
if (p->f) p->f->c[p->f->c[1] == p] = n;
n->f = p->f, n->c[v] = p;
p->f = n, p->c[v ^ 1] = m;
if (m) m->f = p;
p->update(), n->update();
}
// Splay n so that it is under s (or to root if s is null).
void splay(T *n, T *s = nullptr) {
while (n->f != s) {
T *m = n->f, *l = m->f;
if (l == s)
rotate(n);
else if ((l->c[0] == m) == (m->c[0] == n))
rotate(m), rotate(n);
else
rotate(n), rotate(n);
}
if (!s) root = n;
}
// Get the size of the tree.
int size() { return root->size - 2; }
// Helper function to walk down the tree.
int walk(T *n, int &v, int &pos) {
n->push_down();
int s = n->c[0] ? n->c[0]->size : 0;
(v = s < pos) && (pos -= s + 1);
return s;
}
// Insert node n to position pos.
void insert(T *n, int pos) {
T *c = root;
int v;
++pos;
while (walk(c, v, pos), c->c[v] && (c = c->c[v]))
;
c->c[v] = n, n->f = c, splay(n);
}
// Find the node at position pos. If sp is true, splay it.
T *find(int pos, int sp = true) {
T *c = root;
int v;
++pos;
while ((pos < walk(c, v, pos) || v) && (c = c->c[v]))
;
if (sp) splay(c);
return c;
}
// Find the range [posl, posr) on the splay tree.
T *find_range(int posl, int posr) {
T *r = find(posr), *l = find(posl - 1, false);
splay(l, r);
if (l->c[1]) l->c[1]->push_down();
return l->c[1];
}
// Insert nn of size nn_size to position pos.
void insert_range(T **nn, int nn_size, int pos) {
T *r = find(pos), *l = find(pos - 1, false), *c = l;
splay(l, r);
for (int i = 0; i < nn_size; ++i) c->c[1] = nn[i], nn[i]->f = c, c = nn[i];
for (int i = nn_size - 1; i >= 0; --i) nn[i]->update();
l->update(), r->update(), splay(nn[nn_size - 1]);
}
// Helper function to dealloc a subtree.
void dealloc(T *n) {
if (!n) return;
dealloc(n->c[0]);
dealloc(n->c[1]);
pool.dealloc(n);
}
// Remove from position [posl, posr).
void erase_range(int posl, int posr) {
T *n = find_range(posl, posr);
n->f->c[1] = nullptr, n->f->update(), n->f->f->update(), n->f = nullptr;
dealloc(n);
}
};

} // namespace splay

const int MAXSIZE = 500005;

struct node: splay::reversible_node<node> {
long long val, val_min, label_add;
node(long long v = 0) : splay::reversible_node<node>(), val(v) { val_min = label_add = 0; }
// Add v to the subtree.
void add(long long v) {
val += v;
val_min += v;
label_add += v;
}
void push_down() {
splay::reversible_node<node>::push_down();
for (int t = 0; t < 2; ++t) if (c[t]) c[t]->add(label_add);
label_add = 0;
}
void update() {
splay::reversible_node<node>::update();
val_min = val;
for (int t = 0; t < 2; ++t) if (c[t]) val_min = std::min(val_min, c[t]->val_min);
}
};

splay::tree<node, MAXSIZE, allocator::stack<node, MAXSIZE + 2>> t;

```
1 change: 1 addition & 0 deletions docs/old-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ <h1 id="index--">Index -</h1>
<li><strong><a href="https://thesobersobber.github.io/CP-Snippets/rr-segtree">rr-segtree</a></strong> : best segtree </li>
<li><strong><a href="https://thesobersobber.github.io/CP-Snippets/segtree">segtree</a></strong> : sextree </li>
<li><strong><a href="https://thesobersobber.github.io/CP-Snippets/seive">seive</a></strong> : seive </li>
<li><strong>[splay-tree-rr-sir](<a href="https://thesobersobber.github.io/CP-Snippets/Splay">https://thesobersobber.github.io/CP-Snippets/Splay</a> Tree)</strong> : used here by rr sir, I have no idea how to use it or what it&#39;s used in mostly, <a href="https://atcoder.jp/contests/abc350/submissions/52600529">RR Sir ABC F Submission</a> </li>
<li><strong><a href="https://thesobersobber.github.io/CP-Snippets/tokenizer">tokenizer</a></strong> : tokenizer that has no use </li>
<li><strong><a href="https://thesobersobber.github.io/CP-Snippets/totient-seive">totient-seive</a></strong> : totient-seive </li>
<li><strong><a href="https://thesobersobber.github.io/CP-Snippets/totient">totient</a></strong> : totient </li>
Expand Down
2 changes: 1 addition & 1 deletion docs/tokenizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- ```
https://thesobersobber.github.io/CP-Snippets/tokenizer
```
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2466)
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2661)

```cpp
vec(string) tokenizer(string str,char ch) {std::istringstream var((str)); vec(string) v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}
Expand Down
2 changes: 1 addition & 1 deletion docs/totient-seive.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- ```
https://thesobersobber.github.io/CP-Snippets/totient-seive
```
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2473)
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2668)

```cpp
for (int i = 1; i < MN; i++)
Expand Down
2 changes: 1 addition & 1 deletion docs/totient.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- ```
https://thesobersobber.github.io/CP-Snippets/totient
```
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2487)
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2682)

```cpp
long long totient(long long n) {
Expand Down
2 changes: 1 addition & 1 deletion docs/trie.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- ```
https://thesobersobber.github.io/CP-Snippets/trie
```
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2507)
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2702)

```cpp
struct Trie{
Expand Down
2 changes: 1 addition & 1 deletion docs/troll.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- ```
https://thesobersobber.github.io/CP-Snippets/troll
```
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2543)
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2738)

```cpp
// Assembly Generator: gcc -S -o temp.s fileName.cpp
Expand Down
2 changes: 1 addition & 1 deletion docs/two-sat (kosaraju).md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- ```
https://thesobersobber.github.io/CP-Snippets/two-sat (kosaraju)
```
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2553)
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2748)

```cpp
/**
Expand Down
2 changes: 1 addition & 1 deletion docs/variadic.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- ```
https://thesobersobber.github.io/CP-Snippets/variadic
```
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2690)
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2885)

```cpp
#define f(u, args...) [&](auto &&u) { return args; }
Expand Down
2 changes: 1 addition & 1 deletion docs/xor-basis.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- ```
https://thesobersobber.github.io/CP-Snippets/xor-basis
```
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2699)
- [github-snip-file](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2894)

```cpp
struct XorBasis{
Expand Down
Loading

0 comments on commit 2dba8c6

Please sign in to comment.