Martian Strings

题解:

对于询问串, 我们可以从前往后先跑一遍exkmp。

然后在倒过来,从后往前跑一遍exkmp。

我们就可以记录下 对于每个正向匹配来说,最左边的点在哪里。

对于每个反向匹配来说,最右边的点在哪里。

然后判断可不可以构成这个串就好了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e5 + ;
int n, z[N];
char s[N];
void init(int n){
z[] = n;
int j = , k;
for(int i = ; i < n; i = k){
if(j < i) j = i;
while(j < n && s[j] == s[j-i]) j++;
z[i] = j-i;
k = i+;
while(k + z[k-i] < j)
z[k] = z[k-i],k++;
}
}
char ss[N], t[N];
int l[N], r[N];
int q;
int main(){
scanf("%s", ss);
int lens = strlen(ss);
scanf("%d", &q);
int ans = ;
while(q--){
scanf("%s", t);
int len2 = strlen(t);
for(int i = ; i <= len2; ++i){
l[i] = lens + ;
r[i] = ;
}
strcpy(s, t);
s[len2] = '@';
strcpy(s++len2, ss);
init(lens + + len2);
for(int i = ; i <= lens; ++i){
int t = z[len2+i];
l[t] = min(l[t], i);
}
for(int i = len2-; i >= ; --i)
l[i] = min(l[i], l[i+]);
reverse(s, s+len2);
reverse(s+len2+, s+lens++len2);
init(lens + + len2);
for(int i = ; i <= lens; ++i){
int t = z[len2+i];
r[t] = max(r[t], lens-i+);
}
for(int i = len2-; i >= ; --i)
r[i] = max(r[i], r[i+]);
for(int i = ; i < len2; ++i){
if(l[i] + len2- <= r[len2-i]) {
ans++;
break;
}
}
}
cout << ans << endl;
return ;
}

CodeForces 149E Martian Strings exkmp的更多相关文章

  1. codeforces 149E . Martian Strings kmp

    题目链接 给一个字符串s, n个字符串str. 令tmp为s中不重叠的两个连续子串合起来的结果, 顺序不能改变.问tmp能形成n个字符串中的几个. 初始将一个数组dp赋值为-1. 对str做kmp, ...

  2. CF 149E Martian Strings 后缀自动机

    这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...

  3. Codeforces 149 E. Martian Strings

    正反两遍扩展KMP,维护公共长度为L时.出如今最左边和最右边的位置. . .. 然后枚举推断... E. Martian Strings time limit per test 2 seconds m ...

  4. xtu summer individual-4 D - Martian Strings

    Martian Strings Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  5. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  6. codeforces 112APetya and Strings(字符串水题)

    A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. [Codeforces Round #438][Codeforces 868D. Huge Strings]

    题目链接:868D - Huge Strings 题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值.定义一个新串的价值\(k\)为:最大的\(k\) ...

  8. [Educational Round 5][Codeforces 616F. Expensive Strings]

    这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...

  9. Codeforces 559B - Equivalent Strings

    559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...

随机推荐

  1. 跟着阿里p7一起学java高并发 - 第19天:JUC中的Executor框架详解1,全面掌握java并发核心技术

    这是java高并发系列第19篇文章. 本文主要内容 介绍Executor框架相关内容 介绍Executor 介绍ExecutorService 介绍线程池ThreadPoolExecutor及案例 介 ...

  2. gulp压缩js文件报错日志

    输出 gulp-uglify 压缩js文件时报错信息 gulp.task('es6', function () { return gulp.src('src/main/webapp/bower_com ...

  3. poj 1503 高精度加法

    把输入的数加起来,输入0表示结束. 先看我Java代码,用BigINteger类很多东西都不需要考虑,比如前导0什么的,很方便.不过java效率低点,平均用时600ms,C/C++可以0ms过. im ...

  4. Linux虚拟机所装软件说明

    Linux虚拟机所装软件说明 第一台虚拟机192.168.72.201 的 /usr/local/ 目录下放了一下软件: drwxr-xr-x 3 root root 4096 6月 14 19:16 ...

  5. 【JDK】JDK源码分析-AbstractQueuedSynchronizer(1)

    概述 前文「JDK源码分析-Lock&Condition」简要分析了 Lock 接口,它在 JDK 中的实现类主要是 ReentrantLock (可译为“重入锁”).ReentrantLoc ...

  6. 最全面的改造Zuul网关为Spring Cloud Gateway(包含Zuul核心实现和Spring Cloud Gateway核心实现)

    前言: 最近开发了Zuul网关的实现和Spring Cloud Gateway实现,对比Spring Cloud Gateway发现后者性能好支持场景也丰富.在高并发或者复杂的分布式下,后者限流和自定 ...

  7. Layui多文件上传进度条

    Layui原生upload模块不支持文件上传进度条显示,百度,谷歌找了一下不太适用.后面找到一个别人修改好的JS,替换上去,修改一下页面显示即可使用,一下是部分代码 HTML: <div cla ...

  8. 如何使用dmidecode命令查看硬件信息

    引言 当我们需要获取机器硬件信息时,可使用linux系统自带的dmidecode工具进行查询. dmidecode命令通过读取系统DMI表,显示服务器硬件和BIOS信息.除了可使用dmidecode查 ...

  9. Sublime Text3激活及个性化配置

    [TOC] 在我们的开发过程中,选择正确的开发工具会让我们事半功倍.作为后端开发我们熟悉的myeclipse和itellij idea这些工具我也介绍曾介绍过关于他们的安装及破解.但是我们并不能仅仅使 ...

  10. Android OTG之USB转串口模块通讯

    微信公众号:CodingAndroid CSDN:http://blog.csdn.net/xinpengfei521 1.背景简介 我们公司开发了一款室内机平板APP应用,要求平板能去控制智能门锁. ...