题目:http://codeforces.com/contest/914/problem/F

可以对原字符串的每种字母开一个 bitset 。第 i 位的 1 表示这种字母在第 i 位出现了。

考虑能不能匹配上,可以把可行的 “开头” 设成 1 ;

这样的话,枚举到匹配串的第 i 位,字符是 ch,就找出原字符串里 ch 对应的那个 bitset ,则 bt[ ch ] >> ( i-1 ) 的这些位置可以是合法的开头;

所以每次 ans 每个位置都赋成 1 ,然后对于匹配串的每个位置, & 一下 bt[ ch ] >> ( i-1 ) ,最后看看对应区间里有几个合法的开头就行啦!

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
const int N=1e5+,K=;
int n; char s[N],ch[N];
bitset<N> bt[K],ans,ini;
int main()
{
scanf("%s",ch+); n=strlen(ch+);
for(int i=;i<=n;i++)
bt[ch[i]-'a'][i]=;
for(int i=;i<=n;i++)ini[i]=;
int Q,op,u,l,r,m; char tp[];
scanf("%d",&Q);
while(Q--)
{
scanf("%d",&op);
if(op==)
{
scanf("%d",&u);scanf("%s",tp);
bt[ch[u]-'a'][u]=;
ch[u]=tp[];
bt[ch[u]-'a'][u]=;
}
else
{
scanf("%d%d",&l,&r);scanf("%s",s);
ans=ini; m=strlen(s);
if(m>r-l+){puts("");continue;}
for(int i=;i<m;i++)
ans&=(bt[s[i]-'a']>>i);
int d=(ans>>l).count() - (ans>>(r-m+)).count();
printf("%d\n",d);
}
}
return ;
}

CF 914F Substrings in a String——bitset处理匹配的更多相关文章

  1. 【CodeForces】914 F. Substrings in a String bitset

    [题目]F. Substrings in a String [题意]给定小写字母字符串s,支持两种操作:1.修改某个位置的字符,2.给定字符串y,查询区间[l,r]内出现y多少次.|s|,Σ|y|&l ...

  2. Codeforces 914F. Substrings in a String(bitset)

    比赛的时候怎么没看这题啊...血亏T T 对每种字符建一个bitset,修改直接改就好了,查询一个区间的时候对查询字符串的每种字符错位and一下,然后用biset的count就可以得到答案了... # ...

  3. cf914F. Substrings in a String(bitset 字符串匹配)

    题意 题目链接 Sol Orz jry 和上一个题一个思路吧,直接bitset乱搞,不同的是这次有了修改操作 因为每次修改只会改两个位置,直接暴力改就好了 #include<bits/stdc+ ...

  4. Codeforces 917F Substrings in a String - 后缀自动机 - 分块 - bitset - KMP

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个字母串,要求支持以下操作: 修改一个位置的字母 查询一段区间中,字符串$s$作为子串出现的次数 Solution 1 Bitset 每 ...

  5. Codeforces-914F Substrings in a String (Bitset求T串中S串出现次数)

    之前有过区域赛,简化版问题: 给定一个小写字符组成的字符串S,(|S|<1e5,下标从1开始),现在有Q种操作,对于每个操作Q(Q<=1e5),输入opt, 如果opt==1,输入x,c, ...

  6. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  7. Leetcode: Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  8. CF Two Substrings

    Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  9. [Swift]LeetCode467. 环绕字符串中唯一的子字符串 | Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

随机推荐

  1. js 刷新页面

    Javascript刷新页面的几种方法:1 history.go(0)2 window.location.reload() window.location.reload(true) 3 locatio ...

  2. 小议常被忽略的a标签:visited属性的特殊用法

    CSS1/CSS2对于a定义了4个伪类, :link  a标签未访问时的样式 :active  a标签mousedown时的样式 :hover  a标签mouseover时的样式 :visited  ...

  3. quartz---的Cron表达式

    quartz---的Cron表达式 CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔, ...

  4. transition多个属性同时渐变(left/top)

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  5. 【LeetCode】Unique Binary Search Trees II 异构二叉查找树II

    本文为大便一箩筐的原创内容,转载请注明出处,谢谢:http://www.cnblogs.com/dbylk/p/4048209.html 原题: Given n, generate all struc ...

  6. 用Maven构建Mahout项目

    转载请注明出处:http://blog.fens.me/hadoop-mahout-maven-eclipse/ Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, ...

  7. custom usb-seriel udev relus for compatible usb-seriel devices using kermit

    custom usb-seriel udev relus for compatible usb-seriel devices add-pl2303.rules: ACTION== "add& ...

  8. SQL Server 调优系列基础篇 - 常用运算符总结

    前言 上一篇我们介绍了如何查看查询计划,本篇将介绍在我们查看的查询计划时的分析技巧,以及几种我们常用的运算符优化技巧,同样侧重基础知识的掌握. 通过本篇可以了解我们平常所写的T-SQL语句,在SQL ...

  9. 快速切题sgu127. Telephone directory

    127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...

  10. PADS Layout如何进行“ECO对比更新”

    我们在画PCB中,经常会遇到要修改封装等操作.不推荐直接在pcb中非ECO模式下修改,这样会和orcad原理图不同步.我们采用修改orcad原理图,然后由pads layout软件来自动修改pads ...