2018南京ICPCMediocre String Problem 马拉车
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 马拉车的更多相关文章
- Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细心讲解)
layout: post title: Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细 ...
- ACM-ICPC2018南京赛区 Mediocre String Problem
Mediocre String Problem 题解: 很容易想到将第一个串反过来,然后对于s串的每个位置可以求出t的前缀和它匹配了多少个(EXKMP 或者 二分+hash). 然后剩下的就是要处理以 ...
- 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 ...
- ACM-ICPC 2018 南京赛区网络预赛 J.sum
A square-free integer is an integer which is indivisible by any square number except 11. For example ...
- ACM-ICPC 2018 南京赛区网络预赛 E题
ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...
- ACM-ICPC 2018 南京赛区网络预赛B
题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...
- 计蒜客 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 ...
- 计蒜客 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 ...
- ACM-ICPC 2018 南京赛区网络预赛
轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K Alice, a student of g ...
随机推荐
- smartgit 过期
进入到安装目录把Setting.xml 文件删除然后,再次打开就可以正常使用了.
- K-means + PCA + T-SNE 实现高维数据的聚类与可视化
使用matlab完成高维数据的聚类与可视化 [idx,Centers]=kmeans(qy,) [COEFF,SCORE,latent] = pca(qy); SCORE = SCORE(:,:); ...
- centos下部署jenkins
本文摘抄自:https://www.cnblogs.com/edward2013/p/5284503.html ,请支持原版! 1. 安装JDK 1 yum -y install java 2.安装 ...
- POJ 3784 Running Median(动态维护中位数)
Description For this problem, you will write a program that reads in a sequence of 32-bit signed int ...
- 作业 20181120-3 Beta发布
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2408 小组介绍 组长:付佳 组员:张俊余 李文涛 孙赛佳 田良 于洋 段 ...
- “Hello World!”团队第六周的第一次会议
今天是我们团队“Hello World!”团队第六周召开的第一次会议.博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.Todo List 六.会议照片 七.燃尽图 一.会议时间 ...
- 用P4对数据平面进行编程
引言 SDN架构强调了对控制平面的可编程,数据平面只负责转发,导致数据平面很大程度上受制于功能固定的包处理硬件. P4语言的特性: 目标无关性:P4语言不受制于具体设备,所有可编程芯片都可以使用P4编 ...
- Alpha-end
前言 失心疯病源10 团队代码管理github 个人感悟 肝不动了,肝不动了.明天如果见不到我,不要太想我. 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 熬夜肝代码 代码签入git ...
- ACM-ICPC 2018 沈阳赛区网络预赛
Supreme Number 1000ms 131072K A prime number (or a prime) is a natural number greater than 111 tha ...
- JavaScript DOM编程艺术学习笔记-第二章JavaScript语法
一.JavaScript示例 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...