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. 《图解 HTTP 》阅读 —— 第四章

    第4章 返回结果的HTTP状态码 1XX 接收的请求正在处理 2XX 请求被处理 200 请求成功 204 请求成功,但是没有返回数据 206 客户端进行了范围请求 3XX 重定向 301 永久性重定 ...

  2. Tess4J -4.0.2- Linux 实践 [解决:Tess4J - Native library (linux-x86-64/libtesseract.so) not found in resource path]

    [本文编写于2018年7月5日] Tess4J是Tesseract的Java JNA wrapper.本文介绍了在CentOS 7 操作系统中使用Tess4J的步骤及注意事项.在正式开始之前,先花一点 ...

  3. #Ubuntu 18.04 安装tensorflow-gpu 1.9

    参考 https://tensorflow.google.cn/install/install_linux http://nvidia.com/cuda http://developer.nvidia ...

  4. Centos7 Ntp 时间服务器

    Centos7 Ntp 时间服务器 安装环境 [root@m02 ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 安装 ...

  5. hadoop Datanode Uuid unassigned

    在配置hadoop的hdfs的时候,要首先格式化,然后才能启动,但是格式化的方式有的是不对出现Initialization failed for Block pool <registering& ...

  6. python3【基础】-list&tuple

    一.list概述 list (列表)是python中最常用的数据类型之一,通过列表可以对数据实现最方便的存储,修改等操作.在python3中,list支持如下方法: Help on class lis ...

  7. 利用box-shadow制作loading图

    我们见过很多利用css3做的loading图,像下面这种应该是很常见的.通常制作这种loading,我们会一个标签对应一个圆,八个圆就要八个标签.但是这种做法很浪费资源.我们可以只用一个标签,然后利用 ...

  8. 4. 基本socket函数

    一.创建socket /* 创建一个socket */ int socket(int family, int type, int protocol); /* 参数说明 */ // domain:使用哪 ...

  9. 用VS测试程序

    怀着一种忐忑的心情,我开始了我的软件测试. #include "stdio.h" #include "stdlib.h" int main(int argc, ...

  10. eclipse连接SQL2008R2

    最近又开始写JAVA WEB了,想起连接数据库就麻烦,但是通过一天的努力我居然弄好了,很有成就感. 我用的是 SQL Server 2008 R2  +  eclipse 首先要成功的安装好SQL最终 ...