CodeForces 149E Martian Strings exkmp
题解:
对于询问串, 我们可以从前往后先跑一遍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的更多相关文章
- codeforces 149E . Martian Strings kmp
题目链接 给一个字符串s, n个字符串str. 令tmp为s中不重叠的两个连续子串合起来的结果, 顺序不能改变.问tmp能形成n个字符串中的几个. 初始将一个数组dp赋值为-1. 对str做kmp, ...
- CF 149E Martian Strings 后缀自动机
这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...
- Codeforces 149 E. Martian Strings
正反两遍扩展KMP,维护公共长度为L时.出如今最左边和最右边的位置. . .. 然后枚举推断... E. Martian Strings time limit per test 2 seconds m ...
- xtu summer individual-4 D - Martian Strings
Martian Strings Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- codeforces 112APetya and Strings(字符串水题)
A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input ...
- [Codeforces Round #438][Codeforces 868D. Huge Strings]
题目链接:868D - Huge Strings 题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值.定义一个新串的价值\(k\)为:最大的\(k\) ...
- [Educational Round 5][Codeforces 616F. Expensive Strings]
这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...
- Codeforces 559B - Equivalent Strings
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...
随机推荐
- TCP报文指针解释,IP地址
三次握手TCP报文指针内容: 1.URG:紧急指针,当URG=1,表明紧急指针字段有效,告诉系统报文有紧急内容. 2.ACK: 确认指针,当ACK=1,确认号字段有效. 3.PSH:推送指针,当两个 ...
- Android Studio 制作简单的App欢迎页面——基于Android 6.0
在许多的Android App中,我们点击进入时,都可以看到一个欢迎页面,大概持续了几秒,然后跳转至主页面.以下是我开发过程中总结出的一些方法和例子. 一.创建一个新的Activity 首先,新建了一 ...
- poj2909 欧拉素数筛选
刚刚学了一种新的素数筛选法,效率比原先的要高一些,据说当n趋近于无穷大时这个的时间复杂度趋近O(n).本人水平有限,无法证明. 这是道水题,贴代码出来重点是欧拉筛选法.我把原来普通的筛选法贴出来. / ...
- 创建软RAID5
一 创建4块硬盘组软 RAID5 新增四块20G的新硬盘,将四块硬盘分别分区,全部大小都分为一个区,并改 id 为 “ fd ” 1创建阵列mdadm -Cv /dev/md5 - ...
- 数据结构之稀疏矩阵C++版
//只是简单的演示一下,这个实际运用视乎不怎么多,所以java版不再实现 /* 希疏矩阵应用于对数据的压缩,仅仅保留不为0的数据 稀疏矩阵的转置,可以由多种方式,下面演示的稍显简单,时间复杂度略高O( ...
- html的一些基本属性介绍
一.html的属性类型: 1.常见标签属性: a.<h1>:align对其方式 例如:<h1 align="right"> hhhhh</ ...
- java并发编程(十八)----(线程池)java线程池框架Fork-Join
还记得我们在初始介绍线程池的时候提到了Executor框架的体系,到现在为止我们只有一个没有介绍,与ThreadPoolExecutor一样继承与AbstractExecutorService的For ...
- 集成方法 Ensemble
一.bagging 用于基础模型复杂.容易过拟合的情况,用来减小 variance(比如决策树).基础模型之间没有太多联系(相对于boosting),训练可以并行.但用 bagging 并不能有助于把 ...
- sql存储过程中循环批量插入
前几天有一个需求很头痛,部门是有上下级关系的,在给部门的经理赋予角色和权限的时候,通常我们都会认为假如经理A的部门是1,那么我给了他部门1 的管理权限,那么1的下级部门101,102,103 &quo ...
- 送礼物「JSOI 2015」RMQ+01分数规划
[题目描述] 礼品店一共有N件礼物排成一列,每件礼物都有它的美观度.排在第\(i(1\leq i\leq N)\)个位置的礼物美观度为正整数\(A_I\).JYY决定选出其中连续的一段,即编号为礼物\ ...