BZOJ3103 : Palindromic Equivalence
用Manacher可以推出O(n)对相等和不等关系。
将相等的用并查集维护,不等的连边。
然后从1到n,如果该等价类还没被考虑过,则ans*=26-与它不等的考虑过的等价类个数。
#include<cstdio>
#include<cstring>
#define N 1000010
int n,m,i,r,p,f[N<<1],g[N],vis[N],ans=1;char a[N],s[N<<1],col[N];
struct E{int v;E*nxt;}*j,*h[N],pool[N*2],*cur=pool;
inline int min(int a,int b){return a<b?a:b;}
int F(int x){return g[x]==x?x:g[x]=F(g[x]);}
inline void merge(int x,int y){
if(x&1)return;
if(F(x>>=1)==F(y>>=1))return;
g[g[x]]=g[y];
}
inline void add(int x,int y){
if(!x||!y||x&1)return;
j=cur++;j->v=y>>1;j->nxt=h[x>>=1];h[x]=j;
}
int main(){
scanf("%s",a+1),n=std::strlen(a+1);
for(i=1;i<=n;i++)g[i]=i;
for(i=1;i<=n;i++)s[i<<1]=a[i],s[i<<1|1]='#';s[0]='$',s[1]='#',s[m=(n+1)<<1]='@';
for(f[1]=1,i=2;i<m;i++){
for(f[i]=r>i?min(r-i,f[p*2-i]):1;s[i-f[i]]==s[i+f[i]];f[i]++)merge(i+f[i],i-f[i]);
add(i+f[i],i-f[i]);
if(i+f[i]>r)r=i+f[i],p=i;
}
for(i=1;i<=n;i++)if(!col[F(i)]){
for(p=26,j=h[i];j;j=j->nxt)if(col[F(j->v)])if(vis[g[j->v]]<i)vis[g[j->v]]=i,p--;
col[g[i]]=1,ans=1LL*ans*p%1000000007;
}
return printf("%d",ans),0;
}
BZOJ3103 : Palindromic Equivalence的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 最长回文子串-LeetCode 5 Longest Palindromic Substring
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...
- leetcode--5. Longest Palindromic Substring
题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...
- [LeetCode] Longest Palindromic Substring 最长回文串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- No.005:Longest Palindromic Substring
问题: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- Leetcode Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- 【leedcode】 Longest Palindromic Substring
Given a , and there exists one unique longest palindromic substring. https://leetcode.com/problems/l ...
随机推荐
- 代码风格与树形DP
Streaming很惨,不过因为比赛之间没有提交过就没掉(或掉了)rating.第二题是一个树形DP,但是我都在想第一题了,简直作死. 看着神犇的代码我也是醉了...各种宏,真是好好写会死系列. 看到 ...
- hadoop(一):深度剖析hdfs原理
在配置hbase集群将 hdfs 挂接到其它镜像盘时,有不少困惑的地方,结合以前的资料再次学习; 大数据底层技术的三大基石起源于Google在2006年之前的三篇论文GFS.Map-Reduce. ...
- linux ldconfig
http://blog.csdn.net/dante_k7/article/details/7211868 ldconfig的主要用途: 默认搜寻/lilb和/usr/lib,以及配置文件/etc/l ...
- 【wireshark】打开后显示There are no interfaces on which a capture can be done
解决方式:用管理员方式打开wireshark即可
- 分页管理的JSTL实现
userMgr.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...
- [Android Pro] android 混淆文件project.properties和proguard-project.txt
参考文档:http://blog.csdn.net/xueyepiaoling/article/details/8202359转载自:http://glblong.blog.51cto.com/305 ...
- 【图文详解】python爬虫实战——5分钟做个图片自动下载器
python爬虫实战——图片自动下载器 之前介绍了那么多基本知识[Python爬虫]入门知识,(没看的先去看!!)大家也估计手痒了.想要实际做个小东西来看看,毕竟: talk is cheap sho ...
- 按键的使用方法(三)-------verilog
按键的使用方法三:一键三用: 点击.长击和双击. 代码: /********************************Copyright***************************** ...
- 关于Java异常和错误的几个问题
1.Java中什么是Exception? 异常是Java传达给你的系统和程序错误的方式. 在java中,异常功能是通过实现比如Throwable,Exception,RuntimeException之 ...
- Virtual Box创建共享目录
1.先关闭ubuntu,在virtualbox“设置”中找到“共享文件夹”,点击进入,点击右边添加目录按钮,添加windows中要共享的目录,取一个名.比如我在D盘建一个名为share的文件夹,如下图 ...