基础知识介绍

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. MYSQL 索引汇总

    1.MySQL索引类型 先分以下类,MYQL有两大类索引:聚集索引和非聚集索引(只考虑mysql innodb) 聚集索引:在有主键的情况下,主键为聚集索引,其他都是非聚集索引             ...

  2. 【集群实战】sersync

    1. sersync介绍 sersync功能: 实时同步: sersync组成: sersync==inotify+rsync inotify: 监控某个目录下面"文件/目录"是否 ...

  3. 标准库sys

    sys模块的主要函数介绍,结合官方文档说明和实例.This module provides access to some variables used or maintained by the int ...

  4. Android FrameWork学习(二)Android系统源码调试

    通过上一篇 Android FrameWork学习(一)Android 7.0系统源码下载\编译 我们了解了如何进行系统源码的下载和编译工作. 为了更进一步地学习跟研究 Android 系统源码,今天 ...

  5. 清北学堂—2020.3NOIP数学精讲营—Day 1 morning 重点笔记

    qbxt Day 1 morning 重点笔记 --2020.3.8 济南 主讲:钟皓曦 1 正数%负数==正数 负数%正数==负数 负数%负数==负数 a%b的答案的符号取决于a的符号. 2 快速幂 ...

  6. <学习笔记之 JQuery>

    1. mouseenter   当鼠标指针进入(穿过)元素时,触发事件 var is_enter_help = false; $("#help-div").mouseenter(f ...

  7. E. Sasha and Array 矩阵快速幂 + 线段树

    E. Sasha and Array 这个题目没有特别难,需要自己仔细想想,一开始我想了一个方法,不对,而且还很复杂,然后lj提示了我一下说矩阵乘,然后再仔细想想就知道怎么写了. 这个就是直接把矩阵放 ...

  8. 数位dp (2)

    今天继续写几个数位dp F - Balanced Number 题目大意:给你一个区间,让你求这个区间之中满足条件的数字有多少. 这个条件:可以选数的一个位为轴,左右到轴的长度乘上那个数字本身相等的数 ...

  9. 对已经创建的docker container设置开机自启动

    首先显示出所有的容器 docker ps -a #显示所有容器 设置已经建立的容器的开机自启动方法 docker update --restart=always <container ID 根据 ...

  10. 使用天祥TX-1C调试DS18B20温度传感器的收获

    翻查DS18B20的DataSheet编写操作函数,其过程遇到了不少坎,记下来备查. 对于单总线的DS18B20芯片,首先严格按照时序图写出正确的“写0”.“写1”和“读0.1”的基础函数,再以此写出 ...