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. 【iOS】the executable was signed with invalid entitlements

    又遇到了这个问题,貌似之前遇到过,如图所示: 原因:开发证书里没添加手机. PS: Xcode7 除外,据说已经不需要证书了,这里用的是 6.4

  2. UE4 代理 BindRaw和BindUObject

    代理允许您在C++对象上以通用的但类型安全的方式调用成员函数.通过使用代理,可以将其动态地绑定到任何对象的成员函数上,然后在该对象上调用函数,即时调用者不知道该对象的类型也没关系. 任何时候都应该通过 ...

  3. sqoop增量导数据

    sqoop要实现增量导入参数到hive或者hdfs 1.需要在mysql中创建可以自动更新的字段,当插入数据时和更新数据时改字段自动更新,如图中update_time,当数据插入时会记录更新为插入时间 ...

  4. 堆排序(实现c++)

    堆可以看作是一个完全二叉树,分为大顶堆和小顶堆,本文我们以大顶堆为例来实现堆排序. (1)建堆 先把给定的序列转换成一棵完全二叉树,然后逐步对其调整使其每个结点的值都大于其两个子结点的值,因此我们需要 ...

  5. 学习TensorFlow的第一天

    https://www.cnblogs.com/wangxiaocvpr/p/5902086.html

  6. 基于http(s)协议的模板化爬虫设计

    声明:本文为原创,转载请注明出处 本文总共三章,前面两章废话吐槽比较多,想看结果的话,直接看第三章(后续会更新,最近忙着毕设呢,毕设也是我自己做的,关于射频卡的,有时间我也放上来,哈哈). 一,系统总 ...

  7. macos Mojave 出现网络出错 Frame Check Sequence: Bad checksum

    问题描述:使用软电话外呼的时候出现Request Timeout . 端口监听之后通过 Wireshark发现错误:`Frame Check Sequence: Bad checksum`,查看wir ...

  8. react-native 入门基础介绍

    目录 安装 项目 主要目录结构 入口 Home模块 Coobook模块 List模块 novel模块 相关参考 一个简单的demo,用于介绍react-native相关基础信息,主要是针对有兴趣的同学 ...

  9. 使用rpm安装指定版本的docker(1.12.6)

    一.原因 如果系统是Centos7.3,直接使用yum install docker安装的docker版本是1.13.1,导致在创建容器的会报错,错误如下: 所以为了防止安装高版本的docker引发的 ...

  10. ABAP 金额转换成大写

     FUNCTION zzfi_change_amount.*"---------------------------------------------------------------- ...