启发式合并板子(梦幻布丁)
摘要:Link 启发式合并是针对n个集合(总元素个数是O(n))的合并操作,每次将小的集合合并到大的集合 复杂度证明: 考虑每一个元素$$e \in E$$的贡献,如果在某一次合并中该元素被移动,那么集合的大小至少是$$2|E|$$,故复杂度是$$O(nlogn)$$ 具体的题目而言,我们可以看出对于$$
阅读全文
欧拉序+ST表 O(nlogn+q)求LCA
摘要:欧拉序:每次遍历到树上的一个点,就加进欧拉序 如 1 2 3 4 5 这颗树的欧拉序是121343431 这样我们可以发现一个重要的性质:两个点的LCA是欧拉序之间dep最小的点 易发现这是对的,因为LCA肯定会在欧拉序之间,而LCA的祖先不会,因为如果会,说明LCA的这颗子树已经被遍历完了,那
阅读全文
[模板]主席树
摘要:第K小数 #include <iostream> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int N = 100010; struct Node{ int l,r; in
阅读全文
[模板]可持久化Trie
摘要:可持久化Trie模板 最大亦或和 题解 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int M=6e5+10; int n,m; int h[25*M][2]; int
阅读全文
[转载]算法学习笔记(75): Gosper's Hack
摘要:https://zhuanlan.zhihu.com/p/360512296 能快速算出n的集合的k元子集
阅读全文
经典题:map写bfs
摘要:#include<bits/stdc++.h> #define x first #define y second using namespace std; int order[8] = { 4,1,2,3,6,7,8,5 }; int order2[8] = { 1,7,2,4,5,3,6,8 };
阅读全文
莫队+离散化
摘要:#include<bits/stdc++.h> #define ll long long using namespace std; const int N=3e5,M=5e5; int n,m,k,maxn; int a[N],b[N],c[N]; ll num[N]; ll curn; int p
阅读全文
模板:树状数组
摘要:#include<bits/stdc++.h> using namespace std; const int N=500; int a[N]; int ask(int x){ int ans=0; for(;x;x-=x&-x)ans+=a[x],x-=x&-x; return ans; } voi
阅读全文
ST树的创建
摘要:#include<bits/stdc++.h> using namespace std; const int N = 10010; const int M = 13; int n; int a[N]; int f[N][M]; void ST_create() { for (int i = 1; i
阅读全文