Skip to content

Commit 319f787

Browse files
committed
Docs test (written by ChatGPT)
1 parent e1f9704 commit 319f787

16 files changed

Lines changed: 610 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Pair Counting Utilities
3+
documentation_of: ./src/alfred/algorithm/pair-counting.hpp
4+
---
5+
6+
## Description
7+
8+
This file implements a generic pair counting utility, suitable for efficiently counting the number of pairs that satisfy a given comparison function, commonly used for problems like inversion counting.
9+
10+
## Usage Example
11+
12+
```cpp
13+
#include "pair-counting.hpp"
14+
std::vector<int> a = {3, 1, 2};
15+
size_t inv = count_pair(a, std::greater<int>()); // Count inversions
16+
```
17+
18+
## Main Features
19+
- Supports custom comparison functions for pair counting
20+
- Uses merge sort idea, time complexity $O(n \log n)$
21+
- Does not modify the original data (pass by value)
22+
23+
## Important Functions and Time Complexity
24+
25+
| Function | Description | Time Complexity |
26+
| ------------ | --------------------------- | --------------- |
27+
| `count_pair` | Count pairs satisfying comp | $O(n \log n)$ |
28+
29+
## Notes
30+
- Suitable for counting pairs that satisfy any binary relation.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Algorithm Utilities
3+
documentation_of: ./src/alfred/algorithm/utils.hpp
4+
---
5+
6+
## Description
7+
8+
This file provides a set of common algorithm utility functions, including max/min value updates and vector output, to simplify code writing.
9+
10+
## Usage Example
11+
12+
```cpp
13+
#include "utils.hpp"
14+
int x = 1;
15+
chkmax(x, 5); // x = 5
16+
chkmin(x, {2, 3, 4}); // x = 2
17+
std::vector<int> v = {1, 2, 3};
18+
write_vec(v);
19+
```
20+
21+
## Main Features
22+
- Batch max/min update functions
23+
- Supports initializer_list
24+
- Vector output functions, supports single/multi-line
25+
26+
## Important Functions and Time Complexity
27+
28+
| Function | Description | Time Complexity |
29+
| ----------- | ---------------- | --------------- |
30+
| `chkmax` | Max value update | $O(n)$ |
31+
| `chkmin` | Min value update | $O(n)$ |
32+
| `write_vec` | Output vector | $O(n)$ |
33+
34+
## Notes
35+
- Useful for common helper operations in contests and daily development.

documents/alfred/config/fast-io.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Fast Input/Output Utilities
3+
documentation_of: ./src/alfred/config/fast-io.hpp
4+
---
5+
6+
## Description
7+
8+
This file provides fast input and output utilities for C++, including a custom FastIO class for buffered reading and writing, as well as template functions for fast reading and writing of integers and modular integers.
9+
10+
## Usage Example
11+
12+
```cpp
13+
#include "fast-io.hpp"
14+
int x;
15+
fast_read(x);
16+
write(x);
17+
writeln(x);
18+
```
19+
20+
## Main Features
21+
- Fast buffered input and output
22+
- Supports reading and writing of integers and modular integer types
23+
- Allows resizing of the input buffer
24+
- Variadic template for reading multiple variables
25+
26+
## Important Functions and Time Complexity
27+
28+
| Function | Description | Time Complexity |
29+
| ------------ | ------------------------------ | --------------- |
30+
| `fast_read` | Fast read integer(s) | $O(1)$ per int |
31+
| `write` | Fast write integer/modular int | $O(\log n)$ |
32+
| `writeln` | Fast write with newline | $O(\log n)$ |
33+
| `reset_size` | Resize the input buffer | $O(1)$ |
34+
35+
## Notes
36+
- Useful for competitive programming and scenarios requiring high-performance IO.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: IO Synchronization Off Utility
3+
documentation_of: ./src/alfred/config/io-sync-off.hpp
4+
---
5+
6+
## Description
7+
8+
This file provides a utility function to disable synchronization between C++ standard IO streams and C IO, which can significantly speed up input and output operations in C++ programs.
9+
10+
## Usage Example
11+
12+
```cpp
13+
#include "io-sync-off.hpp"
14+
optimizeIO();
15+
```
16+
17+
## Main Features
18+
- Disables stdio and iostream synchronization
19+
- Unties cin/cout for faster IO
20+
21+
## Important Functions and Time Complexity
22+
23+
| Function | Description | Time Complexity |
24+
| ------------ | --------------------------------- | --------------- |
25+
| `optimizeIO` | Disable IO sync and untie streams | $O(1)$ |
26+
27+
## Notes
28+
- Should be called at the beginning of main() for effect.
29+
- Commonly used in competitive programming.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Appear Statistics Data Structure
3+
documentation_of: ./src/alfred/data_structure/appear-statistics.hpp
4+
---
5+
6+
## Description
7+
8+
This file implements the `AppearStats` class, a data structure for efficiently tracking the positions and counts of occurrences of elements in a sequence, supporting fast queries for the first, last, and count of an element in a given range.
9+
10+
## Usage Example
11+
12+
```cpp
13+
#include "appear-statistics.hpp"
14+
std::vector<int> a = {1, 2, 1, 3, 2};
15+
AppearStats<int> stats(a);
16+
int first_pos = stats.first(0, 4, 2); // First occurrence of 2 in [0,4]
17+
int count = stats.count(0, 4, 1); // Count of 1 in [0,4]
18+
```
19+
20+
## Main Features
21+
- Tracks all positions of each unique element
22+
- Supports fast queries for first/last occurrence and count in a range
23+
- Uses discretization for efficient storage
24+
25+
## Important Functions and Time Complexity
26+
27+
| Function | Description | Time Complexity |
28+
| -------- | -------------------------- | --------------- |
29+
| `first` | First occurrence in range | $O(\log n)$ |
30+
| `last` | Last occurrence in range | $O(\log n)$ |
31+
| `count` | Count occurrences in range | $O(\log n)$ |
32+
33+
## Notes
34+
- Useful for range queries on static arrays.
35+
- Indexing is flexible with a base parameter.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: Binary Trie (01-Trie)
3+
documentation_of: ./src/alfred/data_structure/binary-trie.hpp
4+
---
5+
6+
## Description
7+
8+
This file implements a Binary Trie (01-Trie) data structure for efficiently storing and querying binary representations of integers. It supports insertion, minimum/maximum XOR queries, and range queries with upper bounds.
9+
10+
本文件实现了支持下标和区间信息维护的 01-Trie(BinaryTrie),可用于集合异或最值、区间下标查询等。
11+
12+
## Usage Example
13+
14+
```cpp
15+
#include "binary-trie.hpp"
16+
BinaryTrie trie;
17+
trie.insert(5);
18+
uint64_t min_xor = trie.query_min(3);
19+
uint64_t max_xor = trie.query_max(3);
20+
```
21+
22+
## Main Features
23+
- Insert and store integers in binary form
24+
- Query for minimum/maximum XOR with a given value
25+
- Query for values with XOR less than an upper bound
26+
- Maintains min/max index for range queries
27+
28+
- 支持插入、异或最小/最大值查询
29+
- 支持下标区间信息维护
30+
- 支持 upper_bound 异或查询
31+
32+
## Important Functions and Time Complexity
33+
34+
| Function | Description | Time Complexity |
35+
| ----------- | ----------------------------- | --------------- |
36+
| `insert` | Insert integer into trie | $O(B)$ |
37+
| `query_min` | Minimize XOR with given value | $O(B)$ |
38+
| `query_max` | Maximize XOR with given value | $O(B)$ |
39+
| `query_ub` | Query for XOR < upper bound | $O(B)$ |
40+
41+
| Function | Description | Time Complexity |
42+
| ----------- | ------------------ | --------------- |
43+
| `insert` | 插入一个数 | $O(\log V)$ |
44+
| `query_min` | 查询异或最小值 | $O(\log V)$ |
45+
| `query_max` | 查询异或最大值 | $O(\log V)$ |
46+
| `query_ub` | 异或小于上界的区间 | $O(\log V)$ |
47+
48+
Where $B$ is the number of bits (default 30).
49+
50+
## Notes
51+
- Useful for problems involving XOR queries and binary representations.
52+
- Supports index tracking for advanced queries.
53+
54+
- 适用于集合异或、区间最值等问题。
55+
- 支持维护插入元素的下标信息。
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Chtholly Tree Data Structure
3+
documentation_of: ./src/alfred/data_structure/chtholly.hpp
4+
---
5+
6+
## Description
7+
8+
This file implements the Chtholly Tree data structure, which is a set-based interval management structure supporting fast interval assignment, modification, and queries. It is commonly used for range updates and queries on intervals.
9+
10+
## Usage Example
11+
12+
```cpp
13+
#include "chtholly.hpp"
14+
ChthollyTree<int> tree(10, 0); // Range [0,10] initialized to 0
15+
tree.assign(2, 5, 3); // Set [2,5] to 3
16+
```
17+
18+
## Main Features
19+
- Efficient interval splitting and assignment
20+
- Supports custom modification and query functions on intervals
21+
- Uses std::set for ordered interval management
22+
23+
## Important Functions and Time Complexity
24+
25+
| Function | Description | Time Complexity |
26+
| -------- | ---------------------------- | --------------- |
27+
| `assign` | Assign value to interval | $O(\log n)$ |
28+
| `modify` | Modify interval with functor | $O(\log n)$ |
29+
| `query` | Query interval with functor | $O(\log n)$ |
30+
31+
## Notes
32+
- Useful for range assignment and query problems.
33+
- Intervals are managed as [l, r] inclusive.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Discretization Utilities
3+
documentation_of: ./src/alfred/data_structure/discretization.hpp
4+
---
5+
6+
## Description
7+
8+
本文件实现了通用离散化工具类 `Mess`,用于将任意可比较类型的值映射到连续整数区间,便于后续高效处理。
9+
10+
This file provides the Mess class, a utility for discretizing values in a vector, mapping them to a compact index range. It supports insertion, initialization, querying, and checking existence of values.
11+
12+
## Usage Example
13+
14+
```cpp
15+
#include "discretization.hpp"
16+
std::vector<int> a = {100, 200, 100};
17+
Mess<int> mess(a);
18+
int idx = mess.query(200); // 查询 200 离散化后的编号
19+
```
20+
21+
```cpp
22+
#include "discretization.hpp"
23+
std::vector<int> a = {5, 2, 7};
24+
Mess<int> mess(a);
25+
int idx = mess.query(5); // Get discrete index of 5
26+
```
27+
28+
## Main Features
29+
- 支持批量插入、自动去重排序
30+
- 支持原值与离散编号互查
31+
- 支持判断元素是否存在
32+
33+
Discretizes values to compact indices
34+
Supports batch insertion and initialization
35+
Query for discrete index and check existence
36+
37+
## Important Functions and Time Complexity
38+
39+
| Function | Description | Time Complexity |
40+
| -------- | ------------------ | --------------- |
41+
| `insert` | 插入元素 | $O(1)$ |
42+
| `init` | 初始化(排序去重) | $O(n \log n)$ |
43+
| `query` | 查询离散编号 | $O(\log n)$ |
44+
| `exist` | 判断元素是否存在 | $O(\log n)$ |
45+
46+
## Notes
47+
- 适用于需要离散化处理的场景。
48+
- 支持任意可比较类型。
49+
50+
Useful for coordinate compression and mapping values to indices.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Cancelable Disjoint Set Union (DSU)
3+
documentation_of: ./src/alfred/data_structure/dsu/cancel-dsu.hpp
4+
---
5+
6+
## Description
7+
8+
本文件实现了支持撤销操作的并查集(Cancelable DSU),可用于可回溯的合并查找问题。
9+
10+
This file implements a cancelable Disjoint Set Union (DSU) data structure, also known as a union-find with rollback. It supports merging sets, checking connectivity, and undoing previous merge operations efficiently.
11+
12+
## Usage Example
13+
14+
```cpp
15+
#include "cancel-dsu.hpp"
16+
CancelDSU dsu(5);
17+
dsu.merge(1, 2);
18+
dsu.cancel(); // 撤销上一次合并
19+
dsu.cancel(); // Undo last merge
20+
```
21+
22+
## Main Features
23+
- 支持撤销合并操作
24+
- 支持集合大小查询
25+
- 适合可回溯并查集场景
26+
- Supports union, find, and size queries
27+
- Allows rollback (cancel) of previous merge operations
28+
- Maintains history using a stack
29+
30+
## Important Functions and Time Complexity
31+
32+
| Function | Description | Time Complexity |
33+
| -------- | ----------------------------------- | --------------- |
34+
| `merge` | 合并集合 | $O(\alpha(n))$ |
35+
| `cancel` | 撤销合并 | $O(1)$ |
36+
| `find` | 查找根节点 | $O(\alpha(n))$ |
37+
| `same` | Check if two elements are connected | $O(\alpha(n))$ |
38+
39+
## Notes
40+
- 适用于需要撤销操作的并查集问题。
41+
- Useful for offline dynamic connectivity and backtracking problems.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Disjoint Set Union (DSU)
3+
documentation_of: ./src/alfred/data_structure/dsu/dsu.hpp
4+
---
5+
6+
## Description
7+
8+
This file implements the classic Disjoint Set Union (DSU) or Union-Find data structure, supporting efficient union, find, and size queries. It also provides a directed merge operation.
9+
10+
## Usage Example
11+
12+
```cpp
13+
#include "dsu.hpp"
14+
DSU dsu(5);
15+
dsu.merge(1, 2);
16+
bool connected = dsu.same(1, 2);
17+
```
18+
19+
## Main Features
20+
- Supports union, find, and size queries
21+
- Provides both undirected and directed merge
22+
- Uses path compression and union by size
23+
24+
## Important Functions and Time Complexity
25+
26+
| Function | Description | Time Complexity |
27+
| ---------------- | ----------------------------------- | --------------- |
28+
| `merge` | Merge two sets | $O(\alpha(n))$ |
29+
| `find` | Find representative | $O(\alpha(n))$ |
30+
| `same` | Check if two elements are connected | $O(\alpha(n))$ |
31+
| `size` | Get size of set | $O(1)$ |
32+
| `directed_merge` | Merge x into y (directed) | $O(\alpha(n))$ |
33+
34+
## Notes
35+
- Widely used for connectivity queries in graphs.

0 commit comments

Comments
 (0)