摘要: struct TrieNode { int cnt; int nxt[26]; void Init() { cnt = 0; memset(nxt, 0, sizeof(nxt)); } }; struct Trie { static const int MAXN = 4000000; TrieNo 阅读全文
posted @ 2021-01-12 04:38 purinliang 阅读(56) 评论(0) 推荐(0) 编辑
摘要: struct SegmentTree { #define ls (o<<1) #define rs (o<<1|1) static const int MAXN = 100000; int cnt[(MAXN << 2) + 5]; void PushUp(int o) { cnt[o] = cnt 阅读全文
posted @ 2021-01-12 01:21 purinliang 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 下面代码的删除部分是有错的,不能用!!!应该是del[0]没有在Init的时候清空。另外这些函数也太难用了。 代码 /* Treap : 完整版 */ struct Treap { private: static const int TREAP_MAXN = 2e5 + 5; static cons 阅读全文
posted @ 2021-01-12 01:17 purinliang 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 加上logn计算第k大的方法,就可以用于通过“普通平衡树”这道题。 struct BinaryIndexTree { static const int MAXN = 500000 + 10; int n, A[MAXN]; int cnt[MAXN], siz[MAXN]; void InitVal 阅读全文
posted @ 2021-01-12 00:50 purinliang 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 维护点权信息,记得涉及线段树的操作都要套一个tid变换成线段树上的坐标。 struct TreeChain { static const int MAXN = 100000 + 10; struct Edge { struct EdgeNode { int v, nxt; } en[MAXN << 阅读全文
posted @ 2021-01-11 22:54 purinliang 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 题目链接:https://codeforces.com/contest/1467/problem/E 观察 对于某种权值 \(val\) ,若点 \(i\) 的权值 \(a[i]=val\) 则把这个点染成黑色,其他的点染成白色。 定义黑色节点的数量,为权值 \(val\) 的出现次数 \(cnt[ 阅读全文
posted @ 2021-01-10 06:26 purinliang 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 商场有n个物品,每个物品有一个价格a[i],每个物品至多购买1次。商场有m个折扣活动,用(x[i],y[i])表示一次购买x[i]个物品可以免去最便宜的y[i]个物品的价格。问购买恰好k个物品的最小总价格。 https://codeforces.com/contest/1154/problem/F 阅读全文
posted @ 2021-01-04 18:45 purinliang 阅读(300) 评论(0) 推荐(0) 编辑
摘要: int n; namespace MoAlgorithm { static const int MAXM = 3e5 + 10; static const int MAXN = 3e5 + 10; int n, m, BLOCK; struct Node { int l, r, id; bool o 阅读全文
posted @ 2021-01-03 17:26 purinliang 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 狄尔沃斯定理:最小路径覆盖=最长反链 最小不相交路径覆盖:使用最小条数的路径,覆盖每个点恰好1次。 最小可相交路径覆盖:使用最小条数的路径,每个点可以覆盖多次。 最小可相交路径覆盖做一次Floyd传递闭包变成最小不相交路径覆盖。 最小不相交路径覆盖使用二分图匹配:把每个点x拆成x1(出度)和x2(入 阅读全文
posted @ 2021-01-03 14:57 purinliang 阅读(722) 评论(0) 推荐(0) 编辑
摘要: 允许重边,不允许自环。 无向图: 度数矩阵:D[i][i]=deg[i] 邻接矩阵:A[i][j]=edge[i][j]的数量 注意不可以有自环 Laplace矩阵: L=D-A 生成树个数记为 \(t(G)\) 无向图矩阵树定理: 对于所有的i,把Laplace矩阵的第i行和第i列删除,然后计算其 阅读全文
posted @ 2021-01-02 20:25 purinliang 阅读(301) 评论(0) 推荐(0) 编辑