Gym - 100548G The Problem to Slow Down You


依然是回文树。
我们只需要吧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的更多相关文章
- 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 ...
- 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 ...
- 回文自动机 + 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 ...
- The Problem to Slow Down You
The Problem to Slow Down You 输入:t个测试样例,每个样例输入两个字符串 输出:这两对字符串的回文串可以组成多少对本质不同的回文串 题意:给你两个字符串,然后问你这两字符串 ...
- Codeforces Gym 100338B Geometry Problem 计算几何
Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- UVALive - 7041 The Problem to Slow Down You (回文树)
https://vjudge.net/problem/UVALive-7041 题意 给出两个仅包含小写字符的字符串 A 和 B : 求:对于 A 中的每个回文子串,B 中和该子串相同的子串个数的总和 ...
- UVAlive 7041 The Problem to Slow Down You(回文树)
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- The Problem to Slow Down You(Palindromic Tree)
题目链接:http://codeforces.com/gym/100548 今天晚上突然有了些兴致去学习一下数据结构,然后就各种无意中看到了Palindrome Tree的数据结构,据说是2014年新 ...
- Gym - 100548C The Problem Needs 3D Arrays
Problem C. The Problem Needs 3D Arrays Time Limit: 6000MS Memory Limit: 262144KB 64bit IO Format: ...
随机推荐
- datatables 添加excel下载
Datatables 版本 1.10.12 和普通datatables不一样的是: 引入包 <script src="../../vendor/datatables/js/dataTa ...
- 微信支付之JsApi支付
常见问题:金额错误,微信金额是int类型,最小单位为分,即是1 客户端调用微信支付的时候一闪而过:这个原因是因为微信商户后台支付目录地址没设置对,导致js调用的时候验证没通过 .aspx页面设置: x ...
- js篇之对象数据属性与存取器属性
在ECMAScript中,对象属性值可以用一个或两个方法代替,这两个方法就是getter和setter.由getter与与setter定义的属性叫做‘存取器属性’.当程序查询存取器属性的值时,js调用 ...
- 一个tomcat上部署多个项目,并通过不同端口号访问不同的项目
原文:http://www.cnblogs.com/kismetv/p/7228274.html#title3-1 现在以部署两个项目为例: 第一步:修改tomcat下的server.xml文件 配置 ...
- PHP 中解析 url 并得到 url 参数
这里介绍两种对url操作的方法: 1.拿到一个完整url后,如何解析该url得到里面的参数. /** * 解析url中参数信息,返回参数数组 */ function convertUrlQuery($ ...
- PHP获取文件后缀名
PHP获取文件后缀名是PHP学习者常见的一种操作,无论是在面试过程中还是PHP新手自学中.PHP获取文件后缀名都是很普遍的需要掌握的一个知识点. 下面我们就给大家总结介绍PHP获取文件扩展名也就是后缀 ...
- splay好板子
找到一份比较好的板子,链接https://blog.csdn.net/crazy_ac/article/details/8034190 #include<cstdio> #include& ...
- BOM下的属性和方法---上
-------------BOM------------------------------------------------ 三个系统对话框 浏览器可以通过alert().confirm()和 ...
- 【C++ Primer | 15】C++类内存分布
C++类内存分布 书上类继承相关章节到这里就结束了,这里不妨说下C++内存分布结构,我们来看看编译器是怎么处理类成员内存分布的,特别是在继承.虚函数存在的情况下. 下面可以定义一个类,像下面这样: c ...
- 使用RabbitMQ实现延迟任务
场景一:物联网系统经常会遇到向终端下发命令,如果命令一段时间没有应答,就需要设置成超时. 场景二:订单下单之后30分钟后,如果用户没有付钱,则系统自动取消订单. 上述类似的需求是我们经常会遇见的问题. ...