基础知识介绍

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. 8.Python中装饰器是什么?

    Python中装饰器是什么? A Python decorator is a specific change that we make in Python syntax to alter functi ...

  2. mac OS git关联github

    正在更新 mac OS 默认安装了git  git -v 查看版本 mac OS 默认安装了ssh  ssh -v 查看版本 1.设置username和email(github每次commit都会记录 ...

  3. 《Exchange Server 2010 SP1/SP2管理实践》——第2章 搭建Exchange实验环境2.1 网络环境规划...

    本节书摘来自异步社区<Exchange Server 2010 SP1/SP2管理实践>一书中的第2章,第2.1节,作者: 王淑江 更多章节内容可以访问云栖社区"异步社区&quo ...

  4. Ubuntu 14.04 配置samba

    Ubuntu 14.04 配置samba: 安装略 # vi /etc/samba/smb.conf security = user  (在[global]下任意添加) [share] path = ...

  5. C++ 快读快写

    inline int read() { int s=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; c ...

  6. RF(表格数据获取)

    一.表格数据获取 Get Table Cell [locator | row | col] 获取表格数据 Open Browser file:///D:/HBuilderX/workspace/Pro ...

  7. Unity 游戏框架搭建 2019 (四十二、四十三) MonoBehaviour 简化 & 定时功能

    MonoBehaviour 简化 在前两篇,我们完成了第九个示例.为了完善第九个示例,我们复习了类的继承,又学习了泛型和 params 关键字. 我们已经接触了类的继承了.接触继承之前,把类仅仅当做是 ...

  8. Python高级编程-Python一切皆对象

    Python高级编程-Python一切皆对象 Python3高级核心技术97讲 笔记 1. Python一切皆对象 1.1 函数和类也是对象,属于Python的一等公民 ""&qu ...

  9. 网络流 O - Marriage Match IV

    题目链接:https://vjudge.net/contest/299467#problem/O 题目思路:网络流+最短路 这个是一个最短路+最大流,最短路容易,就是跑起点到每一个点的距离. 但是这个 ...

  10. Dynamics 365 基于 Sql Server 2017 安装 报表 问题

    如果使用SQL2017 安装D365 会发现 SSRS与AD不能在同一台服务器上,因为无法安装SSRS,而无SSRS 则D365是无法继续安装的. 所以解决方法有二个: 1.另外准备一台服务器,不需要 ...