世界真的很大
这道题一开始就想了哈希,理论上是可以过的。。
提莫的这道题卡哈希
无可奈何写正解
看题先:
description:
有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,
然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程。
input:
The first line will contain S. The second line will contain T. The length of T will be at most that of S,
and all characters of S and T will be lower-case alphabet characters (in the range a..z).
output:
The string S after all deletions are complete. It is guaranteed that S will not become empty during the deletion process.
这道题一看就先想暴力
每次匹配前面有没有后缀等于t串
发现其实我们就只是想快速知道前面n的长度是不是T串而已
而字符串这个东西不太好比较,只能一个一个的比
比较不好比较的东西,哈希
于是就想到用线段树来维护一个哈希值,每次添加,修改,查询
复杂度 nlogn