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 ...
随机推荐
- [codeforces 241]C. Mirror Box
[codeforces 241]C. Mirror Box 试题描述 Mirror Box is a name of a popular game in the Iranian National Am ...
- 破解TP-Link路由-嗅探PPPoE拨号密码
如果你平时都使用路由器直接上网,那么你还记得你的宽带(ADSL)帐户名和密码吗?忘记密码后又该如何找回呢?别急,本文带你一同找回遗忘的ADSL密码.1.安全性较差的路由器(例如腾达的某些路由器):这里 ...
- 异常详细信息: System.Data.SqlClient.SqlException:用户 'IIS APPPOOL\DefaultAppPool' 登录失败解决办法
1.安全性---登录名---新建登录名 2.常规----搜索 3.添加SERVICE用户-- 4.服务器角色---勾上sysadmin: IIS中: 应用程序池---对应的程序池上右键---高级设置 ...
- 栈应用hanoi
/* 课本p54页*/ #include<stdio.h> #include <iostream> using namespace std; void move(int n, ...
- 【云计算】Dockerfile示例模板
Dockerfile FROM debian:jessie MAINTAINER "Konrad Kleine" USER root ####################### ...
- cocos2dx混合模式应用———制作新手引导高亮区域
先看下效果 制造这个椭圆高亮区域所使用原图是 附上代码 bool HelloWorld::init() { ////////////////////////////// // 1. super ini ...
- MPlayer-ww 增加边看边剪切功能
解压到 D:\MPlayer-ww 运行 copy_font.bat 安装字体 LED_font.ttf 双击 MPlayer_ww_openWith.reg 添加右键播放功能 outformat.i ...
- 《Algorithms算法》笔记:优先队列(2)——二叉堆
二叉堆 1 二叉堆的定义 堆是一个完全二叉树结构(除了最底下一层,其他层全是完全平衡的),如果每个结点都大于它的两个孩子,那么这个堆是有序的. 二叉堆是一组能够用堆有序的完全二叉树排序的元素,并在数组 ...
- Android Session
AsyncHttpClient保持session http://blog.csdn.net/ewrfedf/article/details/21968511
- 为什么内联函数,构造函数,静态成员函数不能为virtual函数
http://blog.csdn.net/freeboy1015/article/details/7635012 为什么内联函数,构造函数,静态成员函数不能为virtual函数? 1> 内联函数 ...