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. 删除iCloud手机备份

    问题描述 系统9.3.5提示iCloud空间即将满,遂清理一下,发现空间主要被备份文件占用,于是想着删除备份文件,但是手机中的清理iCloud列表中并未找到相关备份文件.最终通过Mac电脑中的iClo ...

  2. 关于eclipse导入maven项目

    1:删除其他的配置文件,只需要源码 和 pom文件 2:导入项目,再修改几个地方: 2.1: 所选项目右键- properties - Project Facet,勾上 Dynamic Web Mod ...

  3. ubuntu - 14.04,如何让从托盘消失的输入法图标再次显示出来?

    ubuntu14.04,我也不知道怎么搞的,突然输入法图标就从托盘上消失了,这可真太不方便了,不知道自己当前是否正在使用输入法,怎么能让输入法图标再次显示在托盘上? 解决办法:确保你的“系统设置”中有 ...

  4. async/await 处理异步

    async/ await来发送异步请求,从服务端获取数据,代码很简洁,同时async/await 已经被标准化. 先说一下async的用法,它作为一个关键字放到函数前面,用于表示函数是一个异步函数,因 ...

  5. P3272 [SCOI2011]地板

    \(\color{#0066ff}{ 题目描述 }\) lxhgww的小名叫"小L",这是因为他总是很喜欢L型的东西.小L家的客厅是一个R*C的矩形,现在他想用L型的地板来铺满整个 ...

  6. luogu4449 于神之怒加强版(莫比乌斯反演)

    link 给定n,m,k,计算\(\sum_{i=1}^n\sum_{j=1}^m\gcd(i,j)^k\)对1000000007取模的结果 多组数据,T<=2000,1<=N,M,K&l ...

  7. 使用js实现水波效果

    使用到的工具:jQuery Ripples Plugin 下载安装 git clone https://github.com/sirxemic/jquery.ripples.git 引入jquery, ...

  8. 黑马JavaScript学习一 BOM之Window对象定时器功能

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. shell脚本学习一

    shell脚本是一种程序与linux内核的语言: 第一个shell脚本: #!/bin/bash echo "cxy" 就是输出cxy 如何执行这个脚本呢: cd demo 进入s ...

  10. Vue-Router路由Vue-CLI脚手架和模块化开发 之 路由的动态跳转

    在上一篇的博文中,实现的跳转是在页面中进行实现的 利用vue-router实例方法,使用js对路由进行动态跳转: 1.router.push:参数为路由对象,跳转到指定路由,跳转后会产生历史记录: & ...