Shift - And字符串快速处理 hdu5972+cf
基础知识介绍

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
(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.
,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.
#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;
}
}
}
}
6 seconds
256 megabytes
standard input
standard output
Given a string s, process q queries, each having one of the following forms:
- 1 i c — Change the i-th character in the string to c.
- 2 l r y — 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.
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 i c (1 ≤ i ≤ |s|)
- 2 l r y (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.
For each query of type 2, output the required answer in a separate line.
ababababa
3
2 1 7 aba
1 5 c
2 1 7 aba
3
1
abcdcbc
5
2 1 7 bc
1 4 b
2 4 7 bc
1 2 a
2 1 4 aa
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的更多相关文章
- 如何实现ZBrush中的Alt和Shift键的快速运用
ZBrush是一个数字雕刻和绘画软件,它以强大的功能和直观的工作流程彻底改变了整个三维雕刻行业.在一个简洁的界面中,ZBrush®为当代数字艺术家提供了世界上最先进的工具.利用快捷键能使操作更快捷高效 ...
- Java实现Sunday百万级数据量的字符串快速匹配算法
背景 在平时的项目中,几乎都会用到比较两个字符串时候相等的问题,通常是用==或者equals()进行,这是在数据相对比较少的情况下是没问题的,当数据库中的数据达到几十万甚至是上百万千万的数 ...
- [BZOJ4002][JLOI2015]有意义的字符串-[快速乘法+矩阵乘法]
Description 传送门 Solution 由于这里带了小数,直接计算显然会爆掉,我们要想办法去掉小数. 而由于原题给了暗示:b2<=d<=(b+1)2,我们猜测可以利用$(\fra ...
- as 插件GsonFormat用法(json字符串快速生成javabean)
GsonFormat 主要用于使用Gson库将JSONObject格式的String 解析成实体,该插件可以加快开发进度,使用非常方便,效率高. 插件地址:https://plugins.jetbra ...
- bzoj4002 [JLOI2015]有意义的字符串 快速幂
Description B 君有两个好朋友,他们叫宁宁和冉冉. 有一天,冉冉遇到了一个有趣的题目:输入 b;d;n,求((b+sqrt(D)/2)^N的整数部分,请输出结果 Mod 752844341 ...
- vim之快速查找功能
vim有强大的字符串查找功能. 我们通常在vim下要查找字符串的时候, 都是输入 / 或者 ? 加 需要查找的字符串来进行搜索,比如想搜索 super 这个单词, 可以输入 /super 或者 ...
- indexOf实现引申出来的各种字符串匹配算法
我们在表单验证时,经常遇到字符串的包含问题,比如说邮件必须包含indexOf.我们现在说一下indexOf.这是es3.1引进的API ,与lastIndexOf是一套的.可以用于字符串与数组中.一些 ...
- python 正则表达式与JSON字符串
目录 正则表达式 概括单字符集 匹配单字符 匹配字符集 普通字符与元字符 元字符和普通的字符的混用 数量词{整数|*|+|?} 匹配指规则的字母 贪婪模式 匹配指定长度的字符串 非贪婪模式 匹配指定长 ...
- C++常见问题: 字符串分割函数 split
C++标准库里面没有字符分割函数split ,这可太不方便了,我已经遇到>3次如何对字符串快速分割这个问题了.列几个常用方法以备不时之需. 方法一: 利用STL自己实现split 函数(常用,简 ...
随机推荐
- Mina Basics 02-基础
基础 在第1章中,我们简要介绍了Apache MINA.在本章中,我们将了解客户端/服务器体系结构以及有关基于MINA的服务器和客户端的详细信息. 我们还将基于TCP和UDP公开一些非常简单的服务器和 ...
- Docker容器利用weave实现跨主机互联
Docker容器利用weave实现跨主机互联 环境: 实现目的:实现主机A中容器1与主机B中容器1的网络互联 主机A步骤: ①下载复制weave二进制执行文件(需要internet)[root@192 ...
- js+css制作简单的轮播图带有定时功能
用纯css和JavaScript代码制作带有定时轮播功能的轮播图 <!DOCTYPE html> <html> <head> <meta charset=&q ...
- Edge Weight Assignment(树-异或-贪心)
大意: 给定一棵无根树,要求你任意设置n-1条边的边权. 使得任意叶子节点间边权的XOR值为0: 此时,令f为所有边权数值不同的个数,求最小的f和最大的f. \(\color{Red}{------- ...
- lh的简单图论
lh的简单图论 http://10.64.70.166/problem/1112 lh的简单图论 Description 众所周知,集训队的lh同学txdy,有一天他在写着代码,突然哼起了rapr ...
- Python+Typora博客图片上传
简介 用Typora 写Markdown 1年多了,这个编辑器的确很好用,但就是写完博客复制到博客园时要一个个手动插替换图片非常麻烦.后来发现最新版的Typora 已经支持图片上传功能,在 设置-图像 ...
- 你知道Spring是怎么解析配置类的吗?
彻底读懂Spring(二)你知道Spring是怎么解析配置类的吗? 推荐阅读: Spring官网阅读系列 彻底读懂Spring(一)读源码,我们可以从第一行读起 Spring执行流程图如下: 如果图片 ...
- 【T-SQL】基础——表别名
Som有时候我们需要为表设置别名,这样就可以方便的修改表. 如果在SSMS中,可以点击 Query-> SQL CMD mode --Set Alisa for the table:setvar ...
- XSS检测总结
XSS漏洞介绍 跨站脚本XSS是一种针对网站应用程序的安全漏洞攻击技术.恶意攻击者往web页面插入恶意的Script代码,当用于浏览该页时,嵌入web中的恶意代码就会被执行,从而达到恶意攻击用 ...
- 杂记---主要关于PHP导出excel表格学习
今天上午处理了一下WIN7系统的电脑前置话筒和耳机口无法使用的问题,主要现象是耳机插入后没声音,麦插入话筒说话对方也听不到,后置端口一切正常.刚开始判断肯定是设置的问题,于是用另一台电脑百度搜索“wi ...
