题目:http://codeforces.com/contest/914/problem/F 可以对原字符串的每种字母开一个 bitset .第 i 位的 1 表示这种字母在第 i 位出现了. 考虑能不能匹配上,可以把可行的 “开头” 设成 1 : 这样的话,枚举到匹配串的第 i 位,字符是 ch,就找出原字符串里 ch 对应的那个 bitset ,则 bt[ ch ] >> ( i-1 ) 的这些位置可以是合法的开头: 所以每次 ans 每个位置都赋成 1 ,然后对于匹配串的每个位置, &a…
[题目]F. Substrings in a String [题意]给定小写字母字符串s,支持两种操作:1.修改某个位置的字符,2.给定字符串y,查询区间[l,r]内出现y多少次.|s|,Σ|y|<=10^5,time=6s. [算法]Bitset [题解]假设S的长度为n,那么对每个字符建一个长度为n的bitset,1表示该位置为该字符,修改时直接修改. 查询的时候将字符串y所有的字符的bitset,按顺序错位and,这样最后得到1表示y为子串,count一下即可. 复杂度O(n^2/32),…
比赛的时候怎么没看这题啊...血亏T T 对每种字符建一个bitset,修改直接改就好了,查询一个区间的时候对查询字符串的每种字符错位and一下,然后用biset的count就可以得到答案了... #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<algorithm> #include<bitset> #define ll…
题意 题目链接 Sol Orz jry 和上一个题一个思路吧,直接bitset乱搞,不同的是这次有了修改操作 因为每次修改只会改两个位置,直接暴力改就好了 #include<bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; char s[MAXN], tmp[MAXN]; int N, q; bitset<MAXN> ans, B[27]; main() { scanf("%s %d",…
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个字母串,要求支持以下操作: 修改一个位置的字母 查询一段区间中,字符串$s$作为子串出现的次数 Solution 1 Bitset 每次匹配一段,可以看成,依次考虑每个位置,匹配的位置对应的起点取交集.例如: 大概就这个意思. bitset的count似乎很慢,可以用__builtin_popcount来数中间的位数,然后暴力数两端的位数会快很多.感觉手写倍增法数位数最快.但有人说前面那个内联函数比手写的$O(\log \log…
之前有过区域赛,简化版问题: 给定一个小写字符组成的字符串S,(|S|<1e5,下标从1开始),现在有Q种操作,对于每个操作Q(Q<=1e5),输入opt, 如果opt==1,输入x,c,表示把S[x]改为c,(c是小写字母). 如果opt==2,输入L,R,和字符串T,输出S[L-R]中有多少个字串==T(字符串可以重叠),(|T|<=100). (其中opt==2的询问次数小于1e3) -------------------------------------------分界线---…
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....". Now we have another string p. Your job is to find…
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....". Now we have another string p. Your job is to find…
Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and…
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....". Now we have another string p. Your job is to find…