基础知识介绍

KMP就是不断往前找1的位置,而ShiftAnd经过三步处理已经完成这个迭代的过程了

如果匹配两个字符集有限的字符串的话,那么Shift-And比kmp要快,找区间内某字符串出现的数目也可以只与这个字符串的长度有关。。

Regular Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1650    Accepted Submission(s): 450

Problem Description
Using regular expression to define a numeric string is a very common thing. Generally, use the shape as follows:
(0|9|7) (5|6) (2) (4|5)
Above regular expression matches 4 digits:The first is one of 0,9 and 7. The second is one of 5 and 6. The third is 2. And the fourth is one of 4 and 5. The above regular expression can be successfully matched to 0525, but it cannot be matched to 9634.
Now,giving you a regular expression like the above formula,and a long string of numbers,please find out all the substrings of this long string that can be matched to the regular expression.
 
Input
It contains a set of test data.The first line is a positive integer N (1 ≤ N ≤ 1000),on behalf of the regular representation of the N bit string.In the next N lines,the first integer of the i-th line is ai(1≤ai≤10)

,representing that the i-th position of regular expression has ai

numbers to be selected.Next there are ai

numeric characters. In the last line,there is a numeric string.The length of the string is not more than 5 * 10^6.

 
Output
Output all substrings that can be matched by the regular expression. Each substring occupies one line
 
Sample Input
4
3 0 9 7
2 5 7
2 2 5
2 4 5
09755420524
 
Sample Output
9755
7554
0524
 
Source
 
#include<cstdio>
#include<bitset>
#include<algorithm>
using namespace std;
bitset<>M[],S;
char s[];
int main(){
int n,t,x;
while(scanf("%d",&n)!=EOF){
for(int i=;i<;++i) M[i].reset();
S.reset();
for(int i=;i<=n;++i) {
for(scanf("%d",&t);t--;){
scanf("%d",&x);
M[x].set(i);
}
}
scanf("%s",s);
for(int i=;s[i];++i) {
S<<=;
S.set();
S&=M[s[i]-''];
if(S[n]==) {
char tmp=s[i+];
s[i+]=;
puts(s+i-n+);
s[i+]=tmp;
}
}
}
}
 
 
F. Substrings in a String
time limit per test

6 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Given a string s, process q queries, each having one of the following forms:

  • 1 ic — Change the i-th character in the string to c.
  • 2 lry — Consider the substring of s starting at position l and ending at position r. Output the number of times y occurs as a substring in it.
Input

The first line of the input contains the string s (1 ≤ |s| ≤ 105) of lowercase English letters.

The second line contains an integer q (1 ≤ q ≤ 105)  — the number of queries to process.

The next q lines describe the queries and may have one of the following forms:

  • 1 ic (1 ≤ i ≤ |s|)
  • 2 lry (1 ≤ l ≤ r ≤ |s|)

c is a lowercase English letter and y is a non-empty string consisting of only lowercase English letters.

The sum of |y| over all queries of second type is at most 105.

It is guaranteed that there is at least one query of second type.

All strings are 1-indexed.

|s| is the length of the string s.

Output

For each query of type 2, output the required answer in a separate line.

Examples
Input
ababababa
3
2 1 7 aba
1 5 c
2 1 7 aba
Output
3
1
Input
abcdcbc
5
2 1 7 bc
1 4 b
2 4 7 bc
1 2 a
2 1 4 aa
Output
2
2
1
转载
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<bitset>
#define ll long long
using namespace std;
const int maxn=, inf=1e9;
int n, ty, l, r, x;
bitset<maxn>v[], ans;
char s[maxn], s2[maxn], c;
inline void read(int &k)
{
int f=; k=; char c=getchar();
while(c<'' || c>'') c=='-'&&(f=-), c=getchar();
while(c<='' && c>='') k=k*+c-'', c=getchar();
k*=f;
}
int main()
{
scanf("%s", s+); int len=strlen(s+);
for(int i=;i<=len;i++) v[s[i]-'a'][i]=;
read(n);
for(int i=;i<=n;i++)
{
read(ty);
if(ty==)
{
read(x); scanf("%c", &c);
v[s[x]-'a'][x]=;
v[(s[x]=c)-'a'][x]=;
}
else
{
read(l); read(r);
scanf("%s", s2); int m=strlen(s2);
if(r-l+<m) {puts(""); continue;}
ans.set();
for(int j=;j<m;j++) ans&=(v[s2[j]-'a']>>j);
printf("%d\n", (int)(ans>>(l)).count()-(int)(ans>>(r-m+)).count());
}
}
}

Shift - And字符串快速处理 hdu5972+cf的更多相关文章

  1. 如何实现ZBrush中的Alt和Shift键的快速运用

    ZBrush是一个数字雕刻和绘画软件,它以强大的功能和直观的工作流程彻底改变了整个三维雕刻行业.在一个简洁的界面中,ZBrush®为当代数字艺术家提供了世界上最先进的工具.利用快捷键能使操作更快捷高效 ...

  2. Java实现Sunday百万级数据量的字符串快速匹配算法

    背景       在平时的项目中,几乎都会用到比较两个字符串时候相等的问题,通常是用==或者equals()进行,这是在数据相对比较少的情况下是没问题的,当数据库中的数据达到几十万甚至是上百万千万的数 ...

  3. [BZOJ4002][JLOI2015]有意义的字符串-[快速乘法+矩阵乘法]

    Description 传送门 Solution 由于这里带了小数,直接计算显然会爆掉,我们要想办法去掉小数. 而由于原题给了暗示:b2<=d<=(b+1)2,我们猜测可以利用$(\fra ...

  4. as 插件GsonFormat用法(json字符串快速生成javabean)

    GsonFormat 主要用于使用Gson库将JSONObject格式的String 解析成实体,该插件可以加快开发进度,使用非常方便,效率高. 插件地址:https://plugins.jetbra ...

  5. bzoj4002 [JLOI2015]有意义的字符串 快速幂

    Description B 君有两个好朋友,他们叫宁宁和冉冉. 有一天,冉冉遇到了一个有趣的题目:输入 b;d;n,求((b+sqrt(D)/2)^N的整数部分,请输出结果 Mod 752844341 ...

  6. vim之快速查找功能

    vim有强大的字符串查找功能. 我们通常在vim下要查找字符串的时候, 都是输入 / 或者 ?  加 需要查找的字符串来进行搜索,比如想搜索 super 这个单词, 可以输入  /super  或者 ...

  7. indexOf实现引申出来的各种字符串匹配算法

    我们在表单验证时,经常遇到字符串的包含问题,比如说邮件必须包含indexOf.我们现在说一下indexOf.这是es3.1引进的API ,与lastIndexOf是一套的.可以用于字符串与数组中.一些 ...

  8. python 正则表达式与JSON字符串

    目录 正则表达式 概括单字符集 匹配单字符 匹配字符集 普通字符与元字符 元字符和普通的字符的混用 数量词{整数|*|+|?} 匹配指规则的字母 贪婪模式 匹配指定长度的字符串 非贪婪模式 匹配指定长 ...

  9. C++常见问题: 字符串分割函数 split

    C++标准库里面没有字符分割函数split ,这可太不方便了,我已经遇到>3次如何对字符串快速分割这个问题了.列几个常用方法以备不时之需. 方法一: 利用STL自己实现split 函数(常用,简 ...

随机推荐

  1. 理解分布式一致性:Paxos协议之Multi-Paxos

    理解分布式一致性:Paxos协议之Multi-Paxos Multi-Paxos without failures Multi-Paxos when phase 1 can be skipped Mu ...

  2. java 之 abstract、interface

    abstract (抽象) 用abstract关键字来修饰一个类时,这个类叫做抽象类: 用abstract来修饰一个方法时,该方法叫做抽象方法. 抽象方法:只有方法的声明,没有方法的实现.以分号结束: ...

  3. CentOS上安装比较习惯的代码编辑器

    linux下的vim用起来不是很习惯,可能是能力有限.所以一直在找一种自己比较熟悉的代码编辑器,所以就找到了sublime text,安装方法网上有很多种,比较方便的方法:直接在csdn上下载一个破解 ...

  4. Keepalived搭建LVS高可用性集群系统

    ! Configuration File for keepalived global_defs { notification_email { acassen@firewall.loc failover ...

  5. 编程坑太多,Map 集合怎么也有这么多坑?一不小心又踩了好几个!

    点赞再看,养成习惯,微信搜索『程序通事』,关注就完事了! 点击查看更多历史文章 上一篇 List 踩坑文章中,我们提到几个比较容易踩坑的点.作为 List 集合好兄弟 Map,我们也是天天都在使用,一 ...

  6. 解决php获取不到Authorization问题

    我用的是thinkphp3.2.3, 在使用jwt的时候通过Authorization传递token,但是每次都接收不到,通过修改..htaccess文件,问题成功解决了,下面是的.htaccess文 ...

  7. Coursera课程笔记----计算导论与C语言基础----Week 1

    计算机的基本原理(Week 1) 第一次数学危机 公元前500年,毕达哥拉斯学派,他们相信数是万物的本源:一切数均可表示成整数或者整数之比 然而毕达哥拉斯证明了勾股定理,某些直角三角形的三边比不能用整 ...

  8. Qt读写xml文件

    写xml <root> <element> <sub id=-1></sub> </element> </root> //添加x ...

  9. DoNet:浅淡对delegate的理解

    1 前言 C#的相关文档,MSDN上其实已经很详细了,关于delegate的使用可以参 考MSDN上的文档https://msdn.microsoft.com/zh-cn/library/900fyy ...

  10. vue-cli中浏览器图标的配置

    在VUE全家桶项目里面,这里给大家提供了2种方案,进行浏览器图标的配置. a):先把图片准备好,放在static文件夹下,再找到根目录下的index.html文件,并打开,在HTML文档的<he ...