当前位置:网站首页>Suffix automata (SAM) board from Jly
Suffix automata (SAM) board from Jly
2022-07-29 03:22:00 【Foolish last words】
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;
}
};
边栏推荐
- 军品研制过程-转阶段
- makefile详解
- 简历竟然敢写精通并发编程,那你说说AQS为什么要用双向链表?
- Shardingsphere's level table practice (III)
- Inventory of domestic and foreign project collaborative management software: SAAS and customization become a trend
- 再学EXKMP(EXKMP模板)
- Typescript learning (I)
- C traps and defects Chapter 3 semantic "traps" 3.6 Boundary Calculation and asymmetric boundary
- CUDA GDB prompt: /tmp/tmpxft**** cudafe1.stub. c: No such file or directory.
- Web uploader cannot upload multiple files
猜你喜欢

How does DataGrid export and recover the entire database data, using a single SQL file

力扣刷题之数组序号计算(每日一题7/28)

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

Pp-yoloe details

Calculation of array serial number of force deduction questions (daily question 7/28)

Photo scale correction tool: DxO viewpoint 3 direct mount version

单例模式(饿汉式 懒汉式)

Digital image processing Chapter 10 - image segmentation

Apache文件管理自学笔记——映射文件夹和基于单ip多域名配置apache虚拟机

A case of gradually analyzing the splitting of classes -- colorful ball collisions
随机推荐
Watermelon book learning Chapter 6 -- SVM
STC单片机驱动1.8‘TFT SPI屏幕演示示例(含资料包)
Calculation of array serial number of force deduction questions (daily question 7/28)
Kubernetes-1.24.x feature
一种简单通用的获取函数栈空间大小的方法
【C】数组
单例模式(饿汉式 懒汉式)
The Federal Reserve raised interest rates again, Powell "let go of doves" at 75 basis points, and US stocks reveled
C traps and defects Chapter 3 semantic "traps" 3.7 evaluation order
MYSQL入门与进阶(十二)
LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路
国产ERP有没有机会击败SAP ?
生产部署zabbix5.0笔记
「PHP基础知识」输出圆周率的近似值
暴力递归到动态规划 01 (机器人移动)
A simple and general method to obtain the size of function stack space
Flask的创建的流程day05-06之创建项目
原理知识用得上
Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
西瓜书学习第六章---SVM