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

以前做过一个类似的,但是查询的子串长度最多是10,这个时候就是用bit + hash做了。这是因为改变一个字符,只需改变它后面10个的hash值就够了,多余的不影响,因为查询去不到那里。(只记得是今年的网络赛来的)

但是这题查询只给了一个长度总和,没上一题好做。

这题的思路应该是用bitset查询。

把各个字母拆成不同的bitset,比如abc,拆成

a: 001

b: 010

c: 100

然后,a & (b >> 1) & (c >> 2)即可。

最后统计bitset的L + lent - 1,R区间中有多少个1,这里需要用移位加速,不然TLE.

bitset的第0位,是最右边的。这也刚好, 相当于把整个串反转了    >> 后也可以把不需要的剔除

>> L位,是把左边的无关字符去掉

>> (R - L + 2 - lent)位是可以算出来的

具体就是,从L开始,假设有x位是合法的贡献,那么有L + x - 1 + lent - 1 = R

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int MAXN = 1e5 + ;
bitset<MAXN> f[];
char str[MAXN];
char t[MAXN];
bitset<MAXN> getAns;
void work() {
scanf("%s", str + );
int lenstr = strlen(str + );
for (int i = ; i <= lenstr; ++i) f[str[i] - 'a'][i] = ;
int q;
scanf("%d", &q);
while (q--) {
int op;
scanf("%d", &op);
if (op == ) {
int pos;
scanf("%d%s", &pos, t);
f[str[pos] - 'a'][pos] = ;
str[pos] = t[];
f[str[pos] - 'a'][pos] = ;
} else {
int L, R;
scanf("%d%d%s", &L, &R, t + );
int lent = strlen(t + );
if (lent > R - L + ) {
printf("0\n");
continue;
}
getAns.reset();
getAns = ~getAns;
for (int i = ; i <= lent; ++i) {
getAns &= (f[t[i] - 'a'] >> (i - ));
}
// cout << getAns << endl;
getAns >>= L;
// cout << getAns << endl;
int ans = getAns.count();
getAns >>= (R - L + - lent);
// cout << getAns << endl;
ans -= getAns.count();
printf("%d\n", ans);
}
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined) F. Substrings in a String的更多相关文章

  1. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  3. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  4. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  5. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

随机推荐

  1. wordcount小程序

    wordcount小程序 (1)github网址 https://github.com/yuyuyu960818/count_txt_file (2)PSP表 PSP2.1 PSP阶段 预估耗时 (分 ...

  2. POJ 1795 DNA Laboratory (贪心+状压DP)

    题意:给定 n 个 字符串,让你构造出一个最短,字典序最小的字符串,包括这 n 个字符串. 析:首先使用状压DP,是很容易看出来的,dp[s][i] 表示已经满足 s 集合的字符串以 第 i 个字符串 ...

  3. Ubuntu学习小结(一) 基础知识,系统安装,软件安装,解压缩

    这段时间,抽空研究了一下Ubuntu,虽然也有过到目前为止使用计算机最作死的经历,但目前已经学会了一些最基本的操作.在这里简单的记录一下,算是吸取的教训,供其他人借鉴. 1.装Ubuntu系统.装Ub ...

  4. Mac 使用 NFS 连接 Centos 上的共享文件夹

    Mac 使用 NFS 连接 Centos 上的共享文件夹 NFS介绍 网络文件系统(Network File System,NFS),一种使用于分散式文件系统的协议,由升阳公司开发,于1984年向外公 ...

  5. 一个android dex 转java源码工具

    和dex2jar,smali2java比起来,这个工具至少结果是正确的,前两者对于循环,异常等的处理明显逻辑就是错误的. 该小工具是基于androguard制作,本来是想自己写一个,后来一找居然有现成 ...

  6. 基于注解的AOP配置

    配置文件 spring配置文件中的约束 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns ...

  7. KMP算法不同写法之间区别

    网上之所以有这么多版本的KMP算法,是因为有的人写的是最大长度串版本的,有的人写的是next数组版本的(具体区别看下面博文),有的人写的是next优化版的,有的人写的是未优化的,不同人写的循环方法不同 ...

  8. MySQL数据库之插入显示图片

    图书馆系统项目需要用到好多图片,并且要求存入到数据库中,对这个特别感兴趣,于是上网查了资料,采用C#语言,进行了具体实现. 说明: 功能:往MySQL数据库插入并显示图片: 验证:执行插入功能后,我把 ...

  9. load xml with xls

    you can study xls language in the below link : http://www.w3schools.com/xsl/xsl_languages.asp CSS = ...

  10. throw new Error('Cyclic dependency' + nodeRep)

    近日重装node_modules 依赖之后,项目启动报错 throw new Error('Cyclic dependency' + nodeRep) 查找资料后得知 产生这个 bug 的原因是循环引 ...