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: ...
随机推荐
- VxWorks软件开发项目实例完全解析1-VxWorks简介
1.前言 VxWorks是专门为实时嵌入式系统设计开发的32位操作系统.主要有如下特点: 实时性强 支持多任务 体积小可裁剪 支持多种CPU 支持网络通信串口通信 汇编+标准C的编程模式.支持C++ ...
- js里的回调函数
function a(callback) // 定义一个函数 ,需要传入的参数是callback 然后callback的类型为一个函数{console.log("callback还表示传 ...
- HTML学习笔记08-表格
HTML表格 表格由<table>标签来定义,表格的行由<tr>标签来定义,表格的列由<td>标签来定义 <!DOCTYPE html> <htm ...
- python实现监控windows服务控制开关服务
转载自 :http://www.jb51.net/article/49106.htm #!/usr/bin/env python #-*- encoding:utf-8 -*- "" ...
- C++:vector的用法详解
原文地址:http://blog.csdn.net/hancunai0017/article/details/7032383 vector(向量): C++中的一种数据结构,确切的说是一个类.它相当于 ...
- vue2之对象属性的监听
对象属性监听的两种方法: 1.普通的watch data() { return { frontPoints: 0 } }, watch: { frontPoints(newValue, oldValu ...
- wpf Assembly.LoadFile dll GetType 反射 抛异常 不具有由 URI 识别的资源。
public static void LoadViewFromUri(this Window window, string baseUri) { try { var resourceLocater = ...
- JNI和NDK
作者:十岁的小男孩 QQ:929994365 心之安处即是吾乡 前言 本文试图通过解答以下三个问题来达到学习JNI和NDK的目的.是什么?有什么用?怎么用?文章内容前三节来自下面第一个链接的博主共享, ...
- 完全背包记录路径poj1787 好题
这题有点多重背包的感觉,但还是用完全背包解决,dp[j]表示凑到j元钱时的最大硬币数,pre[j]是前驱,used[j]是凑到j时第i种硬币的用量 △回溯答案时i-pre[i]就是硬币价值 #incl ...
- poj1742 多维背包
普通的多维背包做不了,需要优化一下 但是没有学优化..别的方法也是可以做的 省去一个 表示阶段的 i 维度,dp[j]表示面值为j的钱是否被凑出来了,used[j]表示第i种硬币在凑面值为j的时候被用 ...