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 ...
随机推荐
- Paper Reading - Convolutional Sequence to Sequence Learning ( CoRR 2017 ) ★
Link of the Paper: https://arxiv.org/abs/1705.03122 Motivation: Compared to recurrent layers, convol ...
- 算法笔记(c++)--求一个数的所有质数因子
算法笔记(c++)--求一个数的所有质数因子 先贴题目: 这题不难,恶心在理解上面.最后看评论知道了怎么回事: 2*2*3*3*5=180 按照这逻辑的话应该输入的数由一系列质数相乘出来,所以每次找到 ...
- 如何隐藏掉SQL Server中自带系统数据库,数据表,存储过程等显示文件,只显示用户的数据库,数据表等文件
企业管理器了,----> 编辑该数据库的注册属性--->“常规”属性页下面-->“显示系统数据库和系统对象”的选项去掉
- Linux 150命令之 文件和目录操作命令 chattr lsattr find
chattr添加隐藏权限 lsattr查看隐藏权限 参数 a文件内容不能删除,只能追加 >> [root@mysql tmp]# chattr +a 1.txt [root@mysql t ...
- Python3 解压序列
一 普遍情况: x,y,z = 1,2,3 print("x:",x) # x:1 print("y:",y) # y:2 print("z:&quo ...
- 互评Alpha版本——杨老师粉丝群——Pinball
一.基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评论作品的选题 (1)N(Need,需求) 成语学习对除汉语言专业外的大学生的需求并不是很高,初中生和高中生因为在升学时需要参加语文 ...
- “Hello World!“”团队第五周召开的第二次会议
今天是我们团队“Hello World!”团队第五周召开的第二次会议.也祝大家双十一快乐~~博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七 ...
- J2EE Oa项目上传服务器出现的乱码解决过程
(= =)搞了许久觉得有必要记下来.. 由于我本地的mysql都设置好了,但是服务器的又不能去改它 毕竟还有其他人要用- -: 所以只能是我建的时候去设置一下了, 首先先建数据库 ,表;; creat ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- lintcode-477-被围绕的区域
477-被围绕的区域 给一个二维的矩阵,包含 'X' 和 'O', 找到所有被 'X' 围绕的区域,并用 'X' 填充满. 样例 给出二维矩阵: X X X X X O O X X X O X X O ...