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: ...
随机推荐
- C++ 中的指针、引用以及函数调用中的问题
参考链接:https://www.cnblogs.com/dolphin0520/archive/2011/04/03/2004869.html 函数传参的方式有三种: (1)值传递: (2)引用传递 ...
- C# 汉字与区位码之间的相互转换(中文数字字母可以,支持空格,但是特殊字符未来得及测试)
using System; using System.Text; namespace Test { class MainClass { /// <summary> /// 中文空白字符,用 ...
- Filter功能
在HttpServletRequest到达 Servlet 之前,拦截客户的HttpServletRequest .根据需要检查HttpServletRequest,也可以修改HttpServletR ...
- 使用python命令构建最简单的web服务
可以使用python自带的包建立最简单的web服务器,使用方法: 1)切换到服务器的根目录下 2)输入命令: python -m SimpleHTTPServer 3)使用wget或者在浏览器访问测试 ...
- elasticsearch5.0.1安装 marvel 插件
elasticsearch5.0.1安装 marvel 插件 1.在elasticsearch上安装x-pach插件 在elasticsearch的根目录(每个节点),运行 bin/elasticse ...
- Oracle数据库操作基本语法
创建表 SQL>create table classes( classId number(2), cname varchar2(40), birthda ...
- Android GsmCellLocation.getCellLocation返回NULL
Android GsmCellLocation.getCellLocation返回NULL 1.首先 获取服务 telephonyManager =(TelephonyManager)getSyste ...
- hdu5443 ST表裸题:求区间最大
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #d ...
- 性能测试十二:jmeter进阶之java请求参数化
如项目中的ip.端口号之类的,都可以在此代码中定义 public Arguments getDefaultParameters() { // TODO Auto-generated method st ...
- <转>用 Java 技术创建 RESTful Web 服务
转自:https://www.ibm.com/developerworks/cn/web/wa-jaxrs/#N1017E JAX-RS:一种更为简单.可移植性更好的替代方式 Dustin Amrhe ...