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 ...
随机推荐
- c++中的srand()和rand() 转载 自:http://blog.sina.com.cn/s/blog_624c2c4001012f67.html
今天看了同事写的小程序,发现了其中出现了srand()和rand()这两个我以前没有用过的函数,当然从名字可以看出肯定能随机数有关,于是网查资料知这两个函数配合一起使用来产生随机数的,哈哈,又长知识了 ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- Netbeans 配置英文和默认utf-8编码
JAVA SDK 下载地址 http://www.oracle.com/technetwork/java/javase/downloads 解决办法: 进入netbeans 6.5\etc ,其中ne ...
- 已知局域网IP地址,如何查看mac
arp -a 加对方IP是查对方的MAC地址 转自: http://zhidao.baidu.com/link?url=8sRdpGcjfGQ-C1F9zNub49Mxe3DAR-RCAHDkHvKC ...
- 【转】实战 SSH 端口转发
本文转自:http://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/index.html,至于有什么用,懂的懂! 实战 SSH 端口转发 通 ...
- Java for LeetCode 150 Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- [Android Pro] Android签名与认证详细分析之二(CERT.RSA剖析)
转载自: http://www.thinksaas.cn/group/topic/335449/ http://blog.csdn.net/u010571535/article/details/899 ...
- 使yum保留下载的rpm包
[root@14LN yum]# egrep 'cachedir|keepcache' /etc/yum.conf #cachedir=/var/cache/yum/$basearch/$releas ...
- poj 2406:Power Strings(KMP算法,next[]数组的理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30069 Accepted: 12553 D ...
- 远程登录 - telnet、mstsc等工具的使用及遇到的问题
刚开始是看到老师在用mstsc远程登录oj服务器桌面对“远程登录”一系列的方法开始感兴趣.下面是我的学习笔记及遇到的一些问题的整理. Mstsc - 百度百科:http://baike.baidu.c ...