题面

rt,如果省选没退役就补

SAM的优势:简单明了

先建S的SAM并标记所有节点,之后每次询问直接把T按广义SAM的方法插上去,统计新加的节点到根的状态代表的本质不同子串数,减掉被标记的部分就是T独有的

 #include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int trs[N][],fth[N],len[N],vis[N],ori[N];
int T,t1,t2,lth,tot,lst,cnt,tmp,tep;
char str[N]; vector<int> vec;
int Insert(int ch)
{
int nde=lst,newn=++tot;
lst=newn,len[newn]=len[nde]+;
while(nde&&!trs[nde][ch])
trs[nde][ch]=newn,nde=fth[nde];
if(!nde) fth[newn]=;
else
{
int tran=trs[nde][ch];
if(len[tran]==len[nde]+)
fth[newn]=tran;
else
{
int rnde=++tot;
len[rnde]=len[nde]+,ori[rnde]=ori[tran];
for(int i=;i<=;i++) trs[rnde][i]=trs[tran][i];
fth[rnde]=fth[tran],fth[tran]=fth[newn]=rnde;
while(nde&&trs[nde][ch]==tran)
trs[nde][ch]=rnde,nde=fth[nde];
}
}
return newn;
}
void Clean()
{
for(int i=;i<(int)vec.size();i++)
{
int nde=vec[i];
while(nde&&vis[nde])
vis[nde]=false,nde=fth[nde];
}
}
int main()
{
scanf("%s%d",str+,&T);
lst=tot=,lth=strlen(str+);
for(int i=;i<=lth;i++)
ori[Insert(str[i]-'a')]=true;
while(T--)
{
scanf("%s%d%d",str+,&t1,&t2);
vec.clear(),lst=,lth=strlen(str+);
for(int i=;i<=lth;i++)
vec.push_back(Insert(str[i]-'a'));
long long ans=,anss=;
for(int i=;i<(int)vec.size();i++)
{
int nde=vec[i];
while(nde&&!vis[nde])
{
ans+=len[nde]-len[fth[nde]];
if(ori[nde]) anss+=len[nde]-len[fth[nde]];
vis[nde]=true,nde=fth[nde];
}
}
printf("%lld\n",ans-anss),Clean();
}
return ;
}

最新文章

  1. Table
  2. gulp教程之gulp-minify-css
  3. webdriver 获取佰词斩的单词(涉及字符串转换)
  4. K-means算法及文本聚类实践
  5. 【leetcode❤python】 414. Third Maximum Number
  6. innertext与innerhtml
  7. Tengine新增健康检查模块
  8. JS实现点击按钮,自增输入框个数
  9. IOS支付宝支付出现6002问题的解决办法
  10. 《TCP/IP具体解释》读书笔记(18章)-TCP连接的建立与中止
  11. java动态代理(JDK和cglib实现对比)
  12. [物理学与PDEs]第2章第2节 粘性流体力学方程组 2.1 引言
  13. Disruptor 为什么这么快?
  14. MySQL中间件之ProxySQL(1):简介和安装
  15. PostgreSQL 自动输入密码
  16. 错误:update 忘了加 where
  17. PCL点云特征描述与提取(2)
  18. 使用 urllib 解析 URL 链接
  19. lua元表(metatable)和元方法(metamethod)
  20. 十二、jdk工具之jcmd介绍(堆转储、堆分析、获取系统信息、查看堆外内存)

热门文章

  1. 你不知道的JavaScript——this词法
  2. mycat - 全局序列
  3. python之路--触发器, 储存过程, 事务
  4. wiki 安装
  5. netstat -na 查看有大量TIME_WAIT解决办法(修改内核参数)
  6. Python实现百度贴吧自动顶贴机
  7. IWMS后台上传文章,嵌入音频文件代码
  8. LODOP打印控件进行批量打印
  9. gauss——seidel迭代
  10. poj-1459(网络流-最大流)