题意:给你一个串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. $.when()方法监控ajax请求获取到的数据与普通ajax请求回调获取到的数据的不同

    1.$.when(ajax).done(function(data)}); 2.$.ajax().done(function(data){}); 1中的data被封装进一个对象[data, " ...

  2. [HNOI2004] 打砖块

    1292. [HNOI2004] 打砖块 ★★   输入文件:brike.in   输出文件:brike.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 在一个凹槽中放 ...

  3. 11.事件驱动events

    事件驱动events ==> events.EventEmitter, EventEmitter 的核心就是事件发射与事件监听器功能的封装更详细的 API 文档参见 http://nodejs. ...

  4. 玩转JavaScript module pattern精髓

    JavaScript module pattern是一种常见的javascript编码模式.这种模式本身很好理解,但是有很多高级用法还没有得到大家的注意.本文,我们将回顾这种设计模式,并且介绍一些高级 ...

  5. Firefox不能加载TinyMCE的问题

    不知Firefox的哪个版本开始,经常不能正常加载TinyMCE. 经过分析发现,出问题时总是停留在加载advhr插件(tiny_mce/plugins/advhr/editor_plugin.js) ...

  6. C++ Websites

    C++ Websites C++ 推荐网站 1.cprogramming.com 2.cppreference.com 3.cplusplus.com 4.Boost C++ Library

  7. javascript 执行环境,作用域链和闭包

    首先看下这条语句: (function($) {…})(jQuery): 1.原理: function(arg){…}这就定义了一个匿名函数,参数为arg 而调用函数时,是在函数后面写上括号和实参的, ...

  8. Nginx + Tomcat 负载均衡配置详解

    Nginx常用操作指南一.Nginx 与 Tomcat 安装.配置及优化1. 检查和安装依赖项 yum -y install gcc pcre pcre-devel zlib zlib-devel o ...

  9. Oracle管理监控 之 rac环境密码文件管理

    密码文件作用: 密码文件用于dba用户的登录认证. dba用户:具备sysdba和sysoper权限的用户,即oracle的sys和system用户. RAC环境中多个节点的密码文件应该保证一致,否则 ...

  10. Monkey Tradition---LightOj1319(中国剩余定理模板)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1319 题意:有 n 个猴子,n 棵树,树的高度为 L ,每个猴子刚开始的时候都在树的底 ...