版本比较
板子汇总
正文
增加 33 行删除 33 行
294 行未改动全部展开295296297298299299300301302303408 行未改动全部展开712713714715716716717718719720465 行未改动全部展开118611871188118911901190119111921193119420 行未改动121512161217121812191219122012211222122331 行未改动1255125612571258125912591260126112621263210 行未改动全部展开147414751476147714781478147914801481148214831484148514861487148814881489149014911491149214931494149518 行未改动151415151516151715181518151915201520152115221523152415251526152615271528152915301530153115321533153315341535153515361537153815391540154015411542154315441544154515461547154845 行未改动15941595159615971598159815991600160116021603160416041605160616071607160816091610161016111612161316141615161516161617161816191620162116221622162316241625162634 行未改动166116621663166416651665166616671668166916701670167116721673167316741675167616771678167816791680168116821682168316841685168630 行未改动17171718171917201721172117221723172417241725172617271728172917301730173117321733173417351736173617371738173917391740174117421743174417451745174617471748174911 行未改动294 行未改动全部展开 int v = edge.first, w = edge.second; if(vis[v]) continue; binsiz = 0; dis[v] = w; get_dis(v, u);
for(int i = 1; i <= binsiz; i++){ for(int j = 1; j <= m; j++){ // qry if(bin[i] <= qry[j]) ans[j] |= flg[qry[j] - bin[i]]; }408 行未改动全部展开 for(int i = 1; i <= n; i++){ cout << (st::t[rt[i]].sum ? st::t[rt[i]].cnt : 0) << '\n'; } return 0;} }```
## dsu on tree
465 行未改动全部展开## trie
```cppstruct trie{ int N;//字符集总大小 int N;//字符集总大小 int son[N][26], siz[N], tot; int calc(char c){ return c - 'a'; }20 行未改动 int calc(char c){ return c - 'a'; } void insert(char s[]){ int len = strlen(s); int len = strlen(s); int now = 0; for(int i = 0; i < len; i++){ int digit = calc(s[i]); if(!son[now][digit]){31 行未改动 string s; //s:1-index int n, m; //n:串长度 //m:字符集大小 //m:字符集大小 char s[maxn]; int cnt[maxn]; int x[maxn], y[maxn]; int prex[maxn];210 行未改动全部展开 Cmp_Fn, // 比较函数(默认less<Key>) Tag, // 树类型(默认rb_tree_tag) Node_Update, // 节点策略(必须指定) Alloc // 分配器(默认allocator<char>)> >```
#### 2. 核心参数说明- **Tag**:`rb_tree_tag`(红黑树,推荐)或 `splay_tree_tag`- **Node_Update**:`tree_order_statistics_node_update`(支持排名操作)
#### 3. 关键成员函数```cpp// 插入元素(返回pair<iterator, bool>)iterator insert(const Key& key) iterator insert(const Key& key)
// 删除元素(参数可以是键或迭代器)void erase(iterator it) void erase(iterator it)void erase(const Key& key)
// 查询key的排名(小于key的元素数量)size_type order_of_key(const Key& key) const18 行未改动using namespace __gnu_pbds;
int main() { // 定义类似set的结构 tree<int, null_type, less<int>, rb_tree_tag, tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> tr;
// 插入元素 tr.insert(10); tr.insert(5); tr.insert(20); tr.insert(15);
// 查询操作 cout << "Size: " << tr.size() << endl; // 4 cout << "Rank of 15: " << tr.order_of_key(15) << endl; // 2(0-indexed排名)
// 查询第2小的元素(0-indexed) auto it = tr.find_by_order(2); if (it != tr.end()) if (it != tr.end()) cout << "3rd element: " << *it << endl; // 15
// 范围查询 cout << "Elements in [8,18]: "; for (auto it = tr.lower_bound(8); it != tr.upper_bound(18); it++) cout << *it << " "; // 输出 10 15
// 删除元素 tr.erase(10); cout << "\nAfter erase(10), size: " << tr.size(); // 3
return 0;}```
45 行未改动int main() { // 定义配对堆(大根堆) typedef priority_queue<int, less<int>, pairing_heap_tag> Heap; Heap pq1, pq2;
// 插入元素并保存迭代器 auto it1 = pq1.push(30); pq1.push(10); pq1.push(50); auto it2 = pq2.push(40);
// 修改元素值 pq1.modify(it1, 35); // 30→35
// 合并堆 pq1.join(pq2); // pq2并入pq1
// 堆操作 cout << "Top: " << pq1.top() << endl; // 50 pq1.pop(); cout << "After pop: " << pq1.top() << endl; // 40
// 遍历所有元素(非标准操作) cout << "All elements: "; while (!pq1.empty()) { cout << pq1.top() << " "; // 40 35 10 pq1.pop(); }
return 0;}```
34 行未改动
int main() { // 定义高性能哈希表 gp_hash_table<string, int> ht;
// 插入数据 ht["apple"] = 5; ht["banana"] = 3; ht.insert({"orange", 7});
// 访问元素 cout << "apple: " << ht["apple"] << endl; // 5
// 遍历元素 cout << "All items:\n"; for (auto& p : ht) cout << p.first << ": " << p.second << endl;
// 删除元素 ht.erase("banana"); cout << "After erase, size: " << ht.size(); // 2
return 0;}```
30 行未改动using namespace __gnu_pbds;
int main() { // 定义字典树 typedef trie<string, null_type, trie_string_access_traits<>, typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> Trie; Trie t;
// 插入数据 t.insert("apple"); t.insert("app"); t.insert("banana"); t.insert("application");
// 前缀搜索 "app" auto range = t.prefix_range("app"); cout << "Prefix 'app': "; for (auto it = range.first; it != range.second; ++it) cout << *it << " "; // 输出 app, apple, application
// 删除元素 t.erase("app");
// 再次搜索 cout << "\nAfter erase: "; range = t.prefix_range("app"); for (auto it = range.first; it != range.second; ++it) cout << *it << " "; // 输出 apple, application
return 0;}```
11 行未改动