用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的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. 最长回文子串-LeetCode 5 Longest Palindromic Substring

    题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  3. leetcode--5. Longest Palindromic Substring

    题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...

  4. [LeetCode] Longest Palindromic Substring 最长回文串

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  5. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  6. No.005:Longest Palindromic Substring

    问题: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. Leetcode Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  9. 【leedcode】 Longest Palindromic Substring

    Given a , and there exists one unique longest palindromic substring. https://leetcode.com/problems/l ...

随机推荐

  1. HDOJ 1272 并查集

    小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  2. Linux LAMP环境搭建

    什么是LAMP Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了 ...

  3. dubbo作为消费者注册过程分析

    请支持原创: http://www.cnblogs.com/donlianli/p/3847676.html   作者当前分析的版本为2.5.x.作者在分析的时候,都是带着疑问去查看代码,debug进 ...

  4. 桐桐的贸易--WA

    问题 A: 桐桐的贸易 时间限制: 1 Sec  内存限制: 64 MB提交: 15  解决: 2[提交][状态][讨论版] 题目描述 桐桐家在Allianceance城,好友ROBIN家在Horde ...

  5. 前台js分页,自己手写逻辑

    js代码如下: //设置分页 var pageSize = 10; //设置一次显示多少页 var pageLimit = 5; $(function(){ //查询所有内容 $.post(ctx + ...

  6. HDU 2841 Visible Trees 数论+容斥原理

    H - Visible Trees Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. OSG addEventHandler W键 L键 F键

    // add the state manipulator    viewer->addEventHandler( new osgGA::StateSetManipulator(viewer-&g ...

  8. 关于Java异常和错误的几个问题

    1.Java中什么是Exception? 异常是Java传达给你的系统和程序错误的方式. 在java中,异常功能是通过实现比如Throwable,Exception,RuntimeException之 ...

  9. barrier()函数

    转自:http://blog.chinaunix.net/uid-21961753-id-1810628.html 今天看内核发现disable_preempt这个函数,觉得挺有意思就看了下网上资料, ...

  10. vi 命令 用法(转)

    一.Unix编辑器概述       编辑器是使用计算机的重要工具之一,在各种操作系统中,编辑器都是必不可少的部件.Unix及其相似的ix 操作系统系列中,为方便各种用户在各个不同的环境中使用,提供了一 ...