hash+二分求出最长公共前缀

然后马拉车+前缀和计数

 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-9
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)+
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("data.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int mod = 1e9 + ;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
int lens, lent;
char s[maxn << ], t[maxn], ss[maxn << ];
int d[maxn], r[maxn << ]; int Init() {
int len = strlen ( s + );
ss[] = '$';
ss[] = '#';
int j = ;
for ( int i = ; i <= len; i++ ) ss[j++] = s[i], ss[j++] = '#';
ss[j] = '\0';
return j;
}
void Manacher() {
int len = Init();
int p, mx = ;
for ( int i = ; i < len; i++ ) {
if ( i < mx ) r[i] = min ( r[ * p - i], mx - i );
else r[i] = ;
while ( ss[i - r[i]] == ss[i + r[i]] ) r[i]++;
if ( mx < i + r[i] ) p = i, mx = i + r[i];
}
for ( int i = ; i < len; i++ ) {
if ( ss[i] == '#' && r[i] == ) continue;
int x = i / - r[i] / + , y = i / + r[i] / - ! ( i & );
d[x]++;
d[ ( x + y ) / + ]--;
}
}
ULL p[maxn], h1[maxn], h2[maxn],seed=; ULL getkey ( ULL *a, int l, int r ) {
return ( a[r] - a[l - ] * p[r - l + ] );
}
bool check ( int len, int P, int lent ) {
if ( getkey ( h1, P - len + , P ) == getkey ( h2, lent - len + , lent ) ) return true;
return false;
}
int main() {
p[] = ;
for ( int i = ; i < maxn; i++ ) p[i] = p[i - ] * seed ;
while ( ~scanf ( "%s%s", s + , t + ) ) {
lens = strlen ( s + );
lent = strlen ( t + );
for ( int i = ; i <= lens; i++ ) d[i] = ;
Manacher();
for ( int i = ; i <= lens; i++ ) d[i] += d[i - ];
reverse ( t+, t + lent+ );
for ( int i = ; i <= lens; ++i ) h1[i] = ( h1[i-] * seed + s[i] ) ;
for ( int i = ; i <= lent; ++i ) h2[i] = ( h2[i-] * seed + t[i] ) ;
LL res = ;
for ( int i = ; i < lens; ++i ) {
if ( s[i] != t[lent] ) continue;
int l = , r = min ( lent, i+ ), mid, ans = ;
while ( r >= l ) {
mid = ( l + r ) >> ;
if ( check ( mid, i, lent ) ) ans = mid, l = mid + ;
else r = mid - ;
}
res += ( LL ) ans * d[i + ];
}
printf ( "%lld\n", res );
}
}

2018南京ICPCMediocre String Problem 马拉车的更多相关文章

  1. Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细心讲解)

    layout: post title: Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细 ...

  2. ACM-ICPC2018南京赛区 Mediocre String Problem

    Mediocre String Problem 题解: 很容易想到将第一个串反过来,然后对于s串的每个位置可以求出t的前缀和它匹配了多少个(EXKMP 或者 二分+hash). 然后剩下的就是要处理以 ...

  3. ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall

    题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K   Feeling hungry, a cute hamster decides to o ...

  4. ACM-ICPC 2018 南京赛区网络预赛 J.sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  5. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

  6. ACM-ICPC 2018 南京赛区网络预赛B

    题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...

  7. 计蒜客 30999.Sum-筛无平方因数的数 (ACM-ICPC 2018 南京赛区网络预赛 J)

    J. Sum 26.87% 1000ms 512000K   A square-free integer is an integer which is indivisible by any squar ...

  8. 计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)

    A. An Olympian Math Problem 54.28% 1000ms 65536K   Alice, a student of grade 66, is thinking about a ...

  9. ACM-ICPC 2018 南京赛区网络预赛

    轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K   Alice, a student of g ...

随机推荐

  1. [寒假学习笔记](一)Markdown语法学习

    Markdown 学习 在博客园上使用markdown编辑,记录学习进度,以来日可以复习 前期准备 1. 安装markdownpad2 官网直接找下载安装,遇到bug他会自动提示信息,跟着提示去安装一 ...

  2. Literature Books

    Lean In (Sheryl Sandberg) Option B (Sheryl Sandberg) Ready Player One

  3. 如何计算FOB价格

    FOB价格是国际贸易术语常有的一种算法,针对不同的对象,FOB价格也有不一样的算法.对于做外贸生意的朋友,需要了解FOB价格以及各项费用名称,以及如何计算FOB价格. FOB价格是国际FOB价格语常有 ...

  4. Java线上应用故障排查之一:高CPU占用 (转)

    一个应用占用CPU很高,除了确实是计算密集型应用之外,通常原因都是出现了死循环. (友情提示:本博文章欢迎转载,但请注明出处:hankchen,http://www.blogjava.net/hank ...

  5. Python 并行分布式框架:Celery 超详细介绍

    本博客摘自:http://blog.csdn.net/liuxiaochen123/article/details/47981111 先来一张图,这是在网上最多的一张Celery的图了,确实描述的非常 ...

  6. C++ map 遍历

    #include <iostream> #include <map> using namespace std; int main(){ map<int,int> m ...

  7. 欢迎来怼第二周Scrum会议六(总第十三次)

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/25  17:19~17:35(总计16min).地点:东 ...

  8. border、margin、padding三者的区别

    当你写前端的时候,肯定会遇到border,margin和padding这几个单词. 如: padding: 16px 0; margin: 0 10px; 在CSS中,他们是表示距离的东西,很多人刚开 ...

  9. 四则运算3+psp0

    题目要求: 1.程序可以判断用户的输入答案是否正确,如果错误,给出正确答案,如果正确,给出提示. 2.程序可以处理四种运算的混合算式. 3.要求两人合作分析,合作编程,单独撰写博客. 团队成员:张绍佳 ...

  10. 团队Alpha冲刺(一)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:丹丹 组员7:家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示组内 ...