当前位置:网站首页>后缀自动机(sam)板子 from jly
后缀自动机(sam)板子 from jly
2022-07-29 03:19:00 【愚末语】
struct SuffixAutomaton {
static constexpr int ALPHABET_SIZE = 26, N = 1e5;
struct Node {
int len;
int link;
int next[ALPHABET_SIZE];
Node() : len(0), link(0), next{} {}
} t[2 * N];
int cntNodes;
SuffixAutomaton() {
cntNodes = 1;
std::fill(t[0].next, t[0].next + ALPHABET_SIZE, 1);
t[0].len = -1;
}
int extend(int p, int c) {
if (t[p].next[c]) {
int q = t[p].next[c];
if (t[q].len == t[p].len + 1)
return q;
int r = ++cntNodes;
t[r].len = t[p].len + 1;
t[r].link = t[q].link;
std::copy(t[q].next, t[q].next + ALPHABET_SIZE, t[r].next);
t[q].link = r;
while (t[p].next[c] == q) {
t[p].next[c] = r;
p = t[p].link;
}
return r;
}
int cur = ++cntNodes;
t[cur].len = t[p].len + 1;
while (!t[p].next[c]) {
t[p].next[c] = cur;
p = t[p].link;
}
t[cur].link = extend(p, c);
return cur;
}
};
边栏推荐
- Photo scale correction tool: DxO viewpoint 3 direct mount version
- Anti vulnerability · benefit from uncertainty --- management?
- Design of smoke temperature, humidity and formaldehyde monitoring based on single chip microcomputer
- 01-SDRAM:初始化模块的代码
- MySQL流程控制之while、repeat、loop循环实例分析
- Typescript学习(一)
- mysql的timestamp存在的时区问题怎么解决
- Introduction and advanced level of MySQL (11)
- MySQL operation database data error: fatal error encoded during command execution
- 3D advanced renderer: artlandis studio 2021.2 Chinese version
猜你喜欢

CentOS install mysql8

Watermelon book learning Chapter 6 -- SVM

Unity 之游戏特效

复现20字符短域名绕过以及xss相关知识点

2.nodejs--路径(_dirname,_filname)、url网址、querystring模块、mime模块、各种路径(相对路径)、网页的加载(面试题*)

今晚7:30 | 连界、将门、百度、碧桂园创投四位大佬眼中的AI世界,是继续高深还是回归商业本质?...

Verilog: blocking assignment and non blocking assignment

【打开新世界大门】看测试老鸟如何把API 测试玩弄在鼓掌之间

Flask creation process day05-06 creation project

Tp5.0 applet users do not need to log in and directly obtain the user's mobile number.
随机推荐
【C】数组
Data truncation and estimation
[freeswitch development practice] media bug obtains call voice flow
「PHP基础知识」输出圆周率的近似值
Introduction to JVM foundation I (memory structure)
Shell script summary
军品三大基线(功能基线、分配基线、产品基线)及基线包含的文件
2022-07-28 study notes of group 4 self-cultivation class (every day)
Unity game special effects
Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
MYCAT read / write separation configuration
MySQL流程控制之while、repeat、loop循环实例分析
How to solve the time zone problem in MySQL timestamp
C陷阱与缺陷 第3章 语义“陷阱” 3.1 指针与数组
带你来浅聊一下,单商户功能模块汇总
一种简单通用的获取函数栈空间大小的方法
原理知识用得上
CUDA GDB prompt: /tmp/tmpxft**** cudafe1.stub. c: No such file or directory.
Chapter 2 VRP command line
Production deployment zabbix5.0 notes