|
| 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 | +- 支持维护插入元素的下标信息。 |
0 commit comments