Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined) F. Substrings in a String
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的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- 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 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 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 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
随机推荐
- 无法认识patch请求
Content-Type: application/vnd.api+jsonbase64:账号密码的设置总结:该及时消化的知识,就应该当时消化.不能拖.注意细节,一个小细节的疏忽,导致自己几乎一天的时 ...
- AJAX的dataType问题
dataType是预期服务器返回的数据类型.如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息来智能判断,比如 XML MIME 类型就被识别为 XML.在 1.4 中,JSON 就会 ...
- Java基础-集合框架的学习大纲
1.List 和 Set 的区别 2.HashSet 是如何保证不重复的 3.HashMap 是线程安全的吗,为什么不是线程安全的(最好画图说明多线程环境下不安全)? 4.HashMap 的扩容过程 ...
- oracle connect by 递归,反递归,自动补全查询实现
递归: select * from t_pams_solution t start with t.id is null connect by prior id = t.parent_id ...
- c#写对象来读取TXT文本文件
本博文让你知道怎样写对象,怎样读取文本文件,怎样根据实际条件判断与获取需要的文本行.参考下面网友的问题,根据源文来看,有些行输出的格式,需要把“,”替换为空格. 第一行还附加入后面的子行每一行的后面, ...
- ASP.NET网页之间传递参数与值
ASP.NET网页之间传递参数与值,方法很多,可以使用Application,Cookie,Session,或是Querystring等等.由于Insus.NET开发的程序中,多数是在后台之间进行参数 ...
- code manager toos TotoiseSVN解锁
TotoiseSVN解锁 一.出现的原因: 1.是开发人员手动锁定了. 2.是由于版本错乱造成的锁定. 二.解决方案: 1.使用客户端解决方案: (1)删除本地副本,重新获取文件. (2)可以先尝试c ...
- 如何在页面中使用svg图标
1.svg图标长啥样 注意:图标的宽高无所谓,使用时可以根据需求修改,fill后面是颜色的填充,可修改图标颜色. <svg viewBox="0 0 1024 1024" v ...
- yum源安装Percona
yum源安装更为简单,方便.话不多说,开始吧. 1.下载yum源 yum -y install https://www.percona.com/redir/downloads/percona-rele ...
- DNS 解析域名以便通过服务器来访问的
域名解析系统 就是把你要访问的网址转换成ip,然后你才能访问的东西 解析www.xxxx.com这类网址为IP来访问服务器 举例: 打个比方 ===>>> 你想去海底捞,但是只知道“ ...