题意

找如下子串的个数:

(l,r)是回文串,并且(l,(l+r)/2)也是回文串

思路

本来写了个回文树+dfs+hash,由于用了map所以T了

后来发现既然该子串和该子串的前半部分都是回文串,所以该子串的前半部分和后半部分是本质相同的!

于是这个log就去掉了

代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1 using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 8e5+100;
const int maxm = 2e6+100;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); const ull base = 201326611; ull po[maxn],ha[maxn]; ull getHash(int l, int r){
return ha[r]-ha[l-1]*po[r-l+1];
}
int ans[maxn];
int id[maxn];
struct pam{
int nx[maxn][26],num[maxn],cnt[maxn],fail[maxn];
int len[maxn],s[maxn],p,lst,n;
int newNode(int x){
mem(nx[p],0);
cnt[p]=num[p]=0;
len[p]=x;
return p++;
}
void init(){
p=0;newNode(0);newNode(-1);
lst=0;n=0;s[0]=-1;fail[0]=1;
}
int getFail(int x){
while(s[n-len[x]-1]!=s[n])x=fail[x];
return x;
}
void add(int x){
x-='a';
s[++n]=x;
int cur=getFail(lst);
if(!(lst=nx[cur][x])){//产生新节点
int now = newNode(len[cur]+2);
fail[now]=nx[getFail(fail[cur])][x];
nx[cur][x]=now;
num[now]=num[fail[now]]+1;
lst=now; id[now]=n;
}
cnt[lst]++;
}
void count(){
for(int i = p-1; i >= 0; i--)cnt[fail[i]]+=cnt[i];
for(int i = 2; i < p; i++){
int l = id[i]-len[i]+1;
int r = id[i];
int mid = (l+r)>>1;
if(len[i]%2==1&&getHash(l,mid)==getHash(mid,r))ans[len[i]]+=cnt[i];
if(len[i]%2==0&&getHash(l,mid)==getHash(mid+1,r))ans[len[i]]+=cnt[i];
}
}
}pam;
int n;
char s[maxn];
int main(){
po[0]=1;
for(int i = 1; i <= 3e5+10; i++){
po[i]=po[i-1]*base;
}
while(~scanf("%s",s+1)){
n=strlen(s+1);
pam.init();
for(int i = 1; i <= n; i++){
ans[i]=0;
ha[i]=ha[i-1]*base+s[i]-'a'+1;
pam.add(s[i]);
}pam.count();
for(int i = 1; i <= n; i++){
printf("%d", ans[i]);
if(i!=n)printf(" ");
}printf("\n");
}
return 0;
}
/* */

HDU 6599 I Love Palindrome String (回文树+hash)的更多相关文章

  1. HDU 5157 Harry and magic string(回文树)

    Harry and magic string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  2. [2019杭电多校第二场][hdu6599]I Love Palindrome String(回文自动机&&hash)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6599 题目大意为求字符串S有多少个子串S[l,r]满足回文串的定义,并且S[l,(l+r)/2]也满足 ...

  3. 杭电多校HDU 6599 I Love Palindrome String (回文树)题解

    题意: 定义一个串为\(super\)回文串为: \(\bullet\) 串s为主串str的一个子串,即\(s = str_lstr_{l + 1} \cdots str_r\) \(\bullet\ ...

  4. hdu多校第二场1009 (hdu6599) I Love Palindrome String 回文自动机/字符串hash

    题意: 找出这样的回文子串的个数:它本身是一个回文串,它的前一半也是一个回文串 输出格式要求输出l个数字,分别代表长度为1~l的这样的回文串的个数 题解: (回文自动机和回文树是一个东西) 首先用回文 ...

  5. HDU 5658 CA Loves Palindromic(回文树)

    CA Loves Palindromic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/O ...

  6. 2019 徐州网络赛 G Colorful String 回文树

    题目链接:https://nanti.jisuanke.com/t/41389 The value of a string sss is equal to the number of differen ...

  7. HDU.5394.Trie in Tina Town(回文树)

    题目链接 \(Description\) 给定一棵\(Trie\).求\(Trie\)上所有回文串 长度乘以出现次数 的和.这里的回文串只能是从上到下的一条链. 节点数\(n\leq 2\times ...

  8. The Preliminary Contest for ICPC Asia Xuzhou 2019 G. Colorful String 回文树

    签到提: 题意:求出每一个回文串的贡献 (贡献的计算就是回文串不同字符的个数) 题解: 用回文树直接暴力即可 回文树开一个数组cost[ ][26] 和val[ ] 数组: val[i]表示回文树上节 ...

  9. Codeforces 932G Palindrome Partition - 回文树 - 动态规划

    题目传送门 通往???的传送点 通往神秘地带的传送点 通往未知地带的传送点 题目大意 给定一个串$s$,要求将$s$划分为$t_{1}t_{2}\cdots t_{k}$,其中$2\mid k$,且$ ...

随机推荐

  1. spring之为什么要使用事务?

    问题描述:现在我们有一个数据库:spring 三张表:account.book.book_stock account存储着用户以及账户余额.book存储着书号.名字和 购买一本所需金额.book_st ...

  2. elk日志使用

    elasticsearch +log4net.ElasticSearch+kibana(windows) 需要的东西(目前用的5.6版本) 1.先安装jdk和jre 配置java环境       2. ...

  3. 源码详解系列(六) ------ 全面讲解druid的使用和源码

    简介 druid是用于创建和管理连接,利用"池"的方式复用连接减少资源开销,和其他数据源一样,也具有连接数控制.连接可靠性测试.连接泄露控制.缓存语句等功能,另外,druid还扩展 ...

  4. MATLAB生成正弦波

    要求:选定采样频率,生成不同频率的正弦波 程序: f1=100;%生成正弦波的频率 fs=1000;%采样频率 N=100;%采样点数 n=0:N-1; t=n/fs;%时间序列 y=sin(2*pi ...

  5. JSP九大内置对象之session以及eclispe如何关联源码

    一.session的特点及其实例 session:同一次会话共享 a.浏览网站:开始->关闭 b.购物:浏览.付款.退出 c.电子邮件:浏览.写邮件.退出  从一次开始到一次结束,是一次会话.  ...

  6. cogs 1001. [WZOI2011 S3] 消息传递 Tarjan

    1001. [WZOI2011 S3] 消息传递 ★★   输入文件:messagew.in   输出文件:messagew.out   简单对比时间限制:1 s   内存限制:128 MB Prob ...

  7. Java小白集合源码的学习系列:Vector

    目录 Vector源码学习 Vector继承体系 Vector核心源码 基本属性 构造器 扩容机制 Enumeration 概述 源码描述 具体操作 Vector总结 Vector源码学习 前文传送门 ...

  8. 状态压缩 hdu #10

    You are playing CSGO. There are n Main Weapons and m Secondary Weapons in CSGO. You can only choose ...

  9. 树形dp - 求树的直径

    随着杭州西湖的知名度的进一步提升,园林规划专家湫湫希望设计出一条新的经典观光线路,根据老板马小腾的指示,新的风景线最好能建成环形,如果没有条件建成环形,那就建的越长越好. 现在已经勘探确定了n个位置可 ...

  10. map + 前缀和

    B. Balanced Substring time limit per test 1 second memory limit per test 256 megabytes input standar ...