用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. 解决港版A1530 ios8 联通4G 电话打不进无法接通的问题,联通4G开关开启方法

    GF的iPhone5s港版A1530联通4G老是出现无法接通的问题, 根本原因是没有4G开关.港行iPhone却只有3G开关.也就是说,当启动3G时,却搜到4G信号,但是关闭时却只能关闭3G和2G.让 ...

  2. 44. log(n)求a的n次方[power(a,n)]

    [题目] 实现函数double Power(double base, int exponent),求base的exponent次方,不需要考虑溢出. [分析] 这是一道看起来很简单的问题,很容易写出如 ...

  3. iOS 和 Android 中的后台运行问题

    后台机制的不同,算是iOS 和 Android的一大区别了,最近发布的iOS7又对后台处理做了一定的更改,找时间总结一下编码上的区别,先做个记录. 先看看iOS的把,首先需要仔细阅读一下Apple的官 ...

  4. sqlserver 中的NOLOCK、HOLDLOCK、UPDLOCK、TABLOCK、TABLOCKX

    1.NOLOCK(不加锁) 此选项被选中时,SQL Server 在读取或修改数据时不加任何锁. 在这种情况下,用户有可能读取到未完成事务(Uncommited Transaction)或回滚(Rol ...

  5. codeforces A. New Year Candles 解题报告

    题目链接:http://codeforces.com/problemset/problem/379/A 题目意思:给定a支蜡烛(每支蜡烛可以燃烧1小时),可以在燃尽的a支蜡烛中看能组成多少组b支蜡烛, ...

  6. Windows下安装Cygwin及包管理器apt-cyg(转)

    本文为转载文章: http://www.2cto.com/os/201212/176551.html Cygwin可以在Windows下使用unix环境Bash和各种功能强大的工具,对于Linux管理 ...

  7. CUDA学习笔记(一)——CUDA编程模型

    转自:http://blog.sina.com.cn/s/blog_48b9e1f90100fm56.html CUDA的代码分成两部分,一部分在host(CPU)上运行,是普通的C代码:另一部分在d ...

  8. JQuery的ajax登录案例

    1.简单版AjaxLogin.html代码: <head> <title></title> <script src="jquery-1.8.3.js ...

  9. BP神经网络模型与学习算法

    一,什么是BP "BP(Back Propagation)网络是1986年由Rumelhart和McCelland为首的科学家小组提出,是一种按误差逆传播算法训练的多层前馈网络,是目前应用最 ...

  10. Android textView点击滚动(跑马灯)效果

    布局文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:to ...