依然是回文树。

我们只需要吧siz[]改成统计两边的siz[][0/1],然后把两个字符中间随便加一个不会出现的字符拼起来,做一遍回文树统计一下就OJBK了

#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const int maxn=500005; int T,n,len[maxn],sum[maxn][2],zt,m,p;
int ch[maxn][27],fl[maxn],cnt,now,c;
char s[maxn];
ll ans; inline void init(){
ans=zt=0,fill(s,s+n+1,0);
for(int i=0;i<=cnt;i++) memset(ch[i],0,sizeof(ch[i]));
for(int i=0;i<=cnt;i++) sum[i][0]=sum[i][1]=0;
fill(len,len+cnt+1,0);
fill(fl,fl+cnt+1,0);
} inline void solve(){
fl[0]=1,len[1]=-1,cnt=now=1; for(int i=1;i<=n;i++,now=ch[now][c],sum[now][zt]++){
if(i>m) zt=1; c=s[i]-'a'; for(;s[i-len[now]-1]!=s[i];now=fl[now]); if(!ch[now][c]){
ch[now][c]=++cnt;
len[cnt]=len[now]+2; if(len[cnt]==1) continue; p=fl[now];
for(;s[i-len[p]-1]!=s[i];p=fl[p]);
fl[cnt]=ch[p][c];
}
} for(int i=cnt;i>=2;i--){
sum[fl[i]][0]+=sum[i][0];
sum[fl[i]][1]+=sum[i][1];
ans+=sum[i][0]*(ll)sum[i][1];
}
} int main(){
scanf("%d",&T);
for(int o=1;o<=T;o++){
init(); scanf("%s",s+1),s[0]='?',m=strlen(s+1);
s[m+1]='z'+1,scanf("%s",s+m+2),n=strlen(s+1); solve(),printf("Case #%d: %I64u\n",o,ans);
} return 0;
}

  

Gym - 100548G The Problem to Slow Down You的更多相关文章

  1. CodeForcesGym 100548G The Problem to Slow Down You

    The Problem to Slow Down You Time Limit: 20000ms Memory Limit: 524288KB This problem will be judged ...

  2. 2014-2015 ACM-ICPC, Asia Xian Regional Contest G The Problem to Slow Down You 回文树

    The Problem to Slow Down You Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjud ...

  3. 回文自动机 + DFS --- The 2014 ACM-ICPC Asia Xi’an Regional Contest Problem G.The Problem to Slow Down You

    The Problem to Slow Down You Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.actio ...

  4. The Problem to Slow Down You

    The Problem to Slow Down You 输入:t个测试样例,每个样例输入两个字符串 输出:这两对字符串的回文串可以组成多少对本质不同的回文串 题意:给你两个字符串,然后问你这两字符串 ...

  5. Codeforces Gym 100338B Geometry Problem 计算几何

    Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  6. UVALive - 7041 The Problem to Slow Down You (回文树)

    https://vjudge.net/problem/UVALive-7041 题意 给出两个仅包含小写字符的字符串 A 和 B : 求:对于 A 中的每个回文子串,B 中和该子串相同的子串个数的总和 ...

  7. UVAlive 7041 The Problem to Slow Down You(回文树)

    题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  8. The Problem to Slow Down You(Palindromic Tree)

    题目链接:http://codeforces.com/gym/100548 今天晚上突然有了些兴致去学习一下数据结构,然后就各种无意中看到了Palindrome Tree的数据结构,据说是2014年新 ...

  9. Gym - 100548C The Problem Needs 3D Arrays

    Problem C.   The Problem Needs 3D Arrays Time Limit: 6000MS Memory Limit: 262144KB 64bit IO Format: ...

随机推荐

  1. Linux磁盘分区、挂载

    ⒈Linux下磁盘说明 1)Linux硬盘分IDE硬盘和SCSI硬盘,目前基本上是SCSI硬盘. 2)对于IDE硬盘,使用“hdx~”标识符,“hd”代表IDE硬盘.   对于SCSI硬盘,使用“sd ...

  2. Cython的简单使用

    Cython是一个快速生成Python扩展模块的工具,从语法层面上来讲是Python语法和C语言语法的混血,当Python性能遇到瓶颈时,Cython直接将C的原生速度植入Python程序,这样使Py ...

  3. TERMIOS详解【转】

    转自:https://blog.csdn.net/guo_wangwei/article/details/1102931# TERMIOS NAME termios, tcgetattr, tcset ...

  4. OA协同办公软件

    OA协同办公软件: 泛微软件. 九思软件. 华天动力. 万户OA.:北京万户网络技术有限公司创立于1998年2月,是北京华宇软件股份有限公司(股票简称:“华宇软件”,股票代码:300271)的全资子公 ...

  5. ES系列十六、集群配置和维护管理

    一.修改配置文件 1.节点配置 1.vim elasticsearch.yml # ======================== Elasticsearch Configuration ===== ...

  6. Vue.js——常用的指令

    1.v-on:指令监听DOM事件,并在触发时运行一些javaScript代码. <div id='myView'> <img src="img/se.png" v ...

  7. 使用ado.net打造通用的数据库操作类

    最近在项目中使用中碰到了这样一种情况,查询的数据是从Oracle中获取的,但是记录下来的数据是存在Sql Server中(企业Oracle数据库管理太严,没办法操作).而且我在之前的工作中也碰到过使用 ...

  8. zabbix系列(二)zabbix3.0.4添加对mysql数据库性能的监控

    zabbix3.0.4添加Mysql的监控 zabbix3.0 server已自带mysql的模板了,只需安装agent端,然后在web端给主机增加模板就行了. Agent端操纵 /etc/zabbi ...

  9. Android service与Thread

    很多时候,你可能会问,为什么要用 Service,而不用 Thread 呢,因为用 Thread 是很方便的,比起 Service 也方便多了,下面我详细的来解释一下. 1). Thread:Thre ...

  10. JavaScript中的事件冒泡?事件传播的解释

    注:本文来源  可译网 事件冒泡是你在学习javaScript旅途中遇到的一个术语,它涉及到当一个元素被另一个元素嵌套时调用事件处理的顺序,并且两个元素注册了同一个事件(例如,点击事件). 但是事件冒 ...