『2019Summer Algorithms』

<> Yes

<First update>
a summer training camp twice, feeling learn all sorts of things, but also all sorts of digging the pit, so he decided to write a summary of the algorithms used to be familiar with the new algorithm, also left a little to understand the new algorithm.


<Text>

AC automaton

Simply put, that is, \ (trie \) tree realize \ (KMP \) , for multi-mode matching strings.

And \ (the AC \) be appreciated automaton is that \ (Fail \) pointer, \ (Fail \) pointer is the key to a multi-pattern matching. After each failed match, \ (Fail \) pointer points to match a current string of this suffix, after several jumps, it can be achieved in a text string \ (Trie \) for all possible matching tree.

For \ (fail \) to solve the pointer, use \ (bfs \) implementation. \ (The AC \) time complexity is automatic machine (in general) linear.

Like \ (AC \) automatic machine and a topological map building optimization , there is no school.

Blog this , the template title here .

manachar algorithm

\ (manacher \) algorithm for solving a string of up to a position of each string palindrome.

In fact, this algorithm and \ (KMP \) thinking about the same, as long as the information is known to push information back on it. Specifically, it can record the current largest palindrome right point, then draw it symmetrical map, you can push, is not difficult.

Blog this , the template title here , you can see \ (HL \ Day4 \) courseware.

ExKMP algorithm

\ (KMP \) algorithm development, also known as \ (z-algorithm \) , to solve the following problems:

Give you two strings \ (S, t \) , each of length \ (n-, m \) , please output \ (S \) is the longest common prefix and suffix t is each.

Thoughts and \ (KMP \) , \ (manacher \) are the same, is pushed from front to back. Since the two positions adjacent to a large part of the answer to duplicate match, so you can consider according to the last answer, we need to discuss the two cases.

Writing is not very good, it seems only index also from \ (0 \) starts from \ (1 \) began to be very awkward.

Blog this , the template title here .

Massive tree

The block thinking on the tree, that tree block.

With \ (DFS \) traverse the tree, the continuous section traverse to the node added in a block. It can then sub-tree to tree information is maintained.

还是和分块一样,块内设法直接维护,边角暴力。这样进行分块是可以支持修改和动态加点的,但是不是稳定算法,会被菊花图卡掉。

模板题这里

树同构

也可以说是树哈希算法,主要用于判定树的形态。

一般来说用的是最小表示法,像树形\(dp\)一样,先获取每个子树的\(hash\)值,然后组合成一个新的序列,再\(hash\)一个值返回即可。

当树是无根树的时候,还要先找以下重心作为根,当然也要考虑双重心的情况。

模板题这里

类欧几里得算法

好像和欧几里得算法没什么关系,是用来计算整除求和式的。

主要思想就是分类,然后分治,比欧几里得算法稍微复杂一点,就是推公式吧,套路还是拆一下求和式,下取整。

模板题这里

整体分治

简单的说就是对于多个询问同时进行二分答案,像二分答案一样判定询问的真实答案位于哪一侧,然后对询问进行分类,就变成一个分治算法了。

真正理解点在于询问分类,这是分治算法的核心,得到的子问题是独立的。这样就可以理解为什么修改操作也能参与分类了。

代码上就是要想好用什么数据结构来维护贡献,然后注意操作的时间顺序就可以了。

模板题:K大数查询Dynamic Rankings,可以看蓝书。

线段树分治

\(cdq\)分治一样,是时间分治的一种。

就是对时间建线段树,然后把一个时间段内存在的操作打在线段树的\(log\)个区间节点上。而对于一个时间点的询问,就对应了线段树的一个叶节点,所以只需将询问挂在叶节点上即可。

在线段树上处理完所有操作和询问后,对整棵线段树\(dfs\)一次,向下访问时依次处理掉节点上的操作,到达叶节点就回答掉询问,向上回溯时就撤销掉操作。

别的都很简单啊,想好用什么数据结构维护操作(要支持撤销)即可。

模板题这里,博客这篇


<后记>

Guess you like

Origin www.cnblogs.com/Parsnip/p/11367604.html