题意:给你一个串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. $.data(elem, key, val) 和 elem.data(key, val)

    var div1 = $("div"),     div2 = $("div"); 1.     div1.data("key", &quo ...

  2. poj2096 Collecting Bugs[期望dp]

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 5394   Accepted: 2670 ...

  3. 正则表达式—RegEx(RegularExpressio)(一)

    今日随笔,想和大家分享一下正则表达式的相关知识. 先不说概念性的东西,举一个例子再说. 验证你输入的邮政编码 ,你输入的邮政编码必须是六位的数字. while (true) { Console.Wri ...

  4. iOS5 ARC学习笔记:strong、weak等详解

    2013-03-25 13:41 佚名 oschina 字号:T | T iOS5中加入了新知识,就是ARC,其实我并不是很喜欢它,因为习惯了自己管理内存.但是学习还是很有必要的.现在我们看看iOS5 ...

  5. redis数据持久化(快照/日志):

    1.RDB快照的配置选项: save // 900内,有1条写入,则产生快照 save // 如果300秒内有1000次写入,则产生快照 save // 如果60秒内有10000次写入,则产生快照 ( ...

  6. windows本地环境如何用wamp配置多域名绑定访问

    https://jingyan.baidu.com/article/acf728fd5fcdadf8e510a3e5.html

  7. 微信小程序 --- 设置app.js/page.js参数的方法

    设置 app.js 文件: //app.js App({ globalData: { is_login:false, userInfo:{} } }) 设置gloabalData的方法: // 定义a ...

  8. Hibernate--快速上手

    一.初识 Hibernate 经典的软件应用体系结构有三层:表示层(提供了与用户交互的接口,实现用户操作界面,展示用户需要的数据).业务逻辑层(完成业务流程,处理表示层提交的数据请求,并将要保存的数据 ...

  9. Oracle HA 之 OGG部署流水

    1.GG组件及其功能简介:    manager进程:总管其他所以进程及处理相应GGSCI命令.    capture进程:从源端的联机日志文件或归档日志文件抓取commit的信息.    sourc ...

  10. scrapy爬虫系列之三--爬取图片保存到本地

    功能点:如何爬取图片,并保存到本地 爬取网站:斗鱼主播 完整代码:https://files.cnblogs.com/files/bookwed/Douyu.zip 主要代码: douyu.py im ...