博客
关于我
bzoj3879: SvT 后缀自动机
阅读量:316 次
发布时间:2019-03-03

本文共 2379 字,大约阅读时间需要 7 分钟。

这一题看了一下,首先反应SAM,肯定是最近SAM做的太多了。。

那么lcp自然就是倒串求LCA啊
嗯,感觉很对
接着再一看,数据有点大
好像不太好。。
那我们有虚树啊!
于是这题就成功地水过去了
感觉这题好题啊,把我最近学的东西都用上了,当然没有线性基。。
但这也说明我最近学得都很扎实,大概可能可以熟练运用了

#include
#include
#include
#include
#include
typedef long long LL;using namespace std;const int N=500005*2;struct qq{int son[26],step,pre;}s[N];int tot,Last;char ss[N];int n,m;void ins (int x){ int p=Last,np=++tot; s[np].step=s[p].step+1; while (p!=0&&s[p].son[x]==0) s[p].son[x]=np,p=s[p].pre; if (p==0) s[np].pre=1; else { int q=s[p].son[x]; if (s[p].step+1==s[q].step) s[np].pre=q; else { int nq=++tot; s[nq]=s[q]; s[nq].step=s[p].step+1; s[q].pre=s[np].pre=nq; while (p!=0&&s[p].son[x]==q) s[p].son[x]=nq,p=s[p].pre; } } Last=np;}int pos[N];struct qr{int x,y,last;}e[N];int num,last[N];void init (int x,int y){ num++; e[num].x=x;e[num].y=y; e[num].last=last[x]; last[x]=num;}int lalal[N],cnt;int f[N][25],dep[N];int dfs (int x,int fa){ lalal[x]=++cnt; dep[x]=dep[fa]+1; f[x][0]=fa; for (int u=1;(1<
<=dep[x];u++) f[x][u]=f[f[x][u-1]][u-1]; for (int u=last[x];u!=-1;u=e[u].last) { int y=e[u].y; dfs(y,x); }}int a[N];bool cmp (int x,int y){ return lalal[x]
=0;u--) if (dep[f[x][u]]>=dep[y]) x=f[x][u]; if (x==y) return x; for (int u=21;u>=0;u--) if (f[x][u]!=f[y][u]) x=f[x][u],y=f[y][u]; return f[x][0]; }int t;void bt ()//建立虚树 { cnt=1;sta[cnt]=1; for (int u=1;u<=t;u++) { int lca=get(a[u],sta[cnt]); if (lca==sta[cnt]) sta[++cnt]=a[u]; else { while (true) { int x=sta[cnt],xx=sta[cnt-1];cnt--; if (xx==lca) { init(xx,x); break; } if (dep[xx]
'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){ x=x*10+ch-'0';ch=getchar();} return x*f;}int main(){ tot=Last=1; n=read();m=read(); scanf("%s",ss+1); for (int u=n;u>=1;u--) { ins(ss[u]-'a'); pos[u]=Last; /* printf("%d %d\n",u,pos[u]); system("pause");*/ } num=0;memset(last,-1,sizeof(last)); for (int u=2;u<=tot;u++) init(s[u].pre,u); dep[0]=0;cnt=0;dfs(1,0); memset(last,-1,sizeof(last)); for (int u=1;u<=m;u++) { num=0; t=read(); for (int u=1;u<=t;u++) { int x=read(); a[u]=pos[x]; tot1[a[u]]=1; } sort(a+1,a+1+t,cmp); int ttt=1; for (int u=2;u<=t;u++) if (a[u]!=a[ttt]) a[++ttt]=a[u]; t=ttt; bt(); ans=0; solve(1);tot1[1]=0; printf("%lld\n",ans); } return 0;}

转载地址:http://lwcq.baihongyu.com/

你可能感兴趣的文章
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>
mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
查看>>
MySQL 8.0 恢复孤立文件每表ibd文件
查看>>
MySQL 8.0开始Group by不再排序
查看>>
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
mysql client library_MySQL数据库之zabbix3.x安装出现“configure: error: Not found mysqlclient library”的解决办法...
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>