题意:给你一个串k,进行两个操作:

“1 a b”:把a位置的字母换成b

“2 l r s”:求l到r有多少个字母和s匹配,匹配的条件是这样:从l开始无限循环s形成一个串ss,然后匹配ss和指定区间的匹配个数,如图。

思路:用树状数组预处理。因为模板串是不断重复循环的,所以我们可以一个位置一个位置求。对于长len的模板串来说,如果位置i,j满足 i%len == j%len,那么i和j匹配时对模板串来说是一样的(匹配同一个字符)。所以我们定义node[字母][模板串长度][相对位置][位置]来遍历某个位置字符在所有可能的相对位置的情况。

参考:Codeforces - 828E DNA Evolution —— 很多棵树状数组

代码:

#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
#define ull unsigned long long
using namespace std;
const int maxn = + ;
const int seed = ;
const int MOD = ;
const int INF = 0x3f3f3f3f;
char s[maxn];
int h[];
int node[][][][maxn];
int lowbit(int x){
return x&(-x);
}
void update(int letter, int x, int val){
for(int i = x; i < maxn; i += lowbit(i)){
for(int len = ; len <= ; len++){
node[letter][len][x % len][i] += val;
}
}
}
int sum(int letter, int x, int len, int pos){
int ans = ;
for(int i = x; i > ; i -= lowbit(i)){
ans += node[letter][len][pos][i];
}
return ans;
}
int query(int l, int r, int len, int letter, int pos){
return sum(letter, r, len, pos) - sum(letter, l - , len, pos);
}
int main(){
memset(node, , sizeof(node));
h['A'] = , h['G'] = , h['C'] = , h['T'] = ;
scanf("%s", s + );
int len = strlen(s + );
for(int i = ; i <= len; i++){
update(h[s[i]], i, );
}
int q;
scanf("%d", &q);
while(q--){
int o,u,v;
char ss[];
scanf("%d", &o);
if(o == ){
scanf("%d%s", &u, ss);
update(h[s[u]], u, -);
update(h[ss[]], u, );
s[u] = ss[];
}
else{
scanf("%d%d%s", &u, &v, ss);
len = strlen(ss);
int ans = ;
for(int i = ; i < len; i++){
ans += query(u, v, len, h[ss[i]], (u + i) % len);
}
printf("%d\n", ans);
}
}
return ;
}
/*
ATGCATGC
4
2 1 8 ATGC
2 2 6 TTT
1 4 T
2 2 6 TA
*/

CodeForces 828E DNA Evolution(树状数组)题解的更多相关文章

  1. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组

    E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that D ...

  2. [Codeforces 1208D]Restore Permutation (树状数组)

    [Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...

  3. Codeforces - 828E DNA Evolution —— 很多棵树状数组

    题目链接:http://codeforces.com/contest/828/problem/E E. DNA Evolution time limit per test 2 seconds memo ...

  4. Codeforces 650D - Zip-line(树状数组)

    Codeforces 题目传送门 & 洛谷题目传送门 我怕不是个 nt--一开始忽略了"询问独立"这个条件--然后就一直在想有什么办法维护全局 LIS--心态爆炸 首先离散 ...

  5. Codeforces 1139F Dish Shopping 树状数组套平衡树 || 平衡树

    Dish Shopping 将每个物品拆成p 和 s 再加上人排序. 然后问题就变成了, 对于一个线段(L - R), 问有多少个(li, ri)满足  L >= li && R ...

  6. Codeforces 830B - Cards Sorting 树状数组

    B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  7. CodeForces 522D Closest Equals 树状数组

    题意: 给出一个序列\(A\),有若干询问. 每次询问某个区间中值相等且距离最短的两个数,输出该距离,没有则输出-1. 分析: 令\(pre_i = max\{j| A_j = A_i, j < ...

  8. codeforces 589G G. Hiring(树状数组+二分)

    题目链接: G. Hiring time limit per test 4 seconds memory limit per test 512 megabytes input standard inp ...

  9. CodeForces–830B--模拟,树状数组||线段树

    B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. JZOJ.5329【NOIP2017模拟8.22】时间机器

    Description

  2. 用Iterator实现遍历集合

    使用Collection类的Iterator,可以方便的遍历Vector, ArrayList, LinkedList等集合元素,避免通过get()方法遍历时,针对每一种对象单独进行编码. 示例: C ...

  3. 【APIO2016】Fireworks[DP 可并堆维护凸包优化]

    4585: [Apio2016]烟火表演 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 100  Solved: 66[Submit][Status] ...

  4. chkconfig --add失败的处理方法

    author: headsen  chen datet:2018-08-30   11:57:49 1,在/etc/init.d/下面添加两个文件,并授予 +X 的权限,效果如下: 2,添加到开启自启 ...

  5. IE各浏览器HACK

    border:2px solid #00f; /*IE.ff的属性*/ border:2px solid #090\9; /* IE6/7/8的属性 */ border:2px solid #F90\ ...

  6. 网络下载功能实现(downloader ) ---- HTML5+

    模块:downloader Downloader模块管理网络文件下载任务,用于从服务器下载各种文件,并支持跨域访问操作.通过plus.downloader获取下载管理对象.Downloader下载使用 ...

  7. network command assistant

    这篇文章收集了久经考验靠谱的命令,也收集了几个比较新的命令.多数命令都可以在图形桌面执行,即使是没什么终端使用经验的Linux用户也会常常执行命令来使用ping或是其它的网络诊断工具. 1.curl ...

  8. mongdb ---shard

    http://blog.fens.me/mongodb-shard/ https://segmentfault.com/a/1190000004263332 1. 和用户管理相关的操作基本都要在adm ...

  9. Android开发新手问题

    因为最近在用空闲时间学习Android开发,期间确实遇到了一些问题.而且因为我之前在公司里一直都是在使用Eclipse进行开发,所以最初我学习Android时也就选择了Google的包含android ...

  10. Winform 下使用WebBrowser的HTML编辑控件—WinHtmlControl 在win7 IE9下的问题

    问题是这样的,有一个需要用到富文本的地方,由于是winform的程序,而且程序是上一代老员工留下的,错误百出,现在要尽量修复,至少保证能正常使用,于是就开始一点点问题修复. 在win7 64位系统下出 ...