codeforces E. DNA Evolution(树状数组)
题目链接:http://codeforces.com/contest/828/problem/E
题解:就是开4个数组举一个例子。
A[mod][res][i]表示到i位置膜mod余数是res的‘A’有多少个。然后以此类推其他碱基。就是单点更新区间求和用树状数组就行具体看一下代码。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int M = 1e5 + ;
char s[M];
int T[][][][M];
inline void add(int id , int mod , int res , int k , int v) {
++k;
while(k < M) {
T[id][mod][res][k] += v;
k += (k & (-k));
}
}
inline int getsum(int id , int mod , int res , int k) {
int ret = ;
++k;
while(k) {
ret += T[id][mod][res][k];
k -= (k & (-k));
}
return ret;
}
int main() {
scanf("%s" ,s);
int q , n , x , l , r;
char c[];
scanf("%d" , &q);
memset(T , , sizeof(T));
int L = strlen(s);
for(int i = ; i < L ; i++) {
for(int j = ; j <= ; j++) {
if(s[i] == 'A') add( , j , i % j , i , );
if(s[i] == 'T') add( , j , i % j , i , );
if(s[i] == 'G') add( , j , i % j , i , );
if(s[i] == 'C') add( , j , i % j , i , );
}
}
while(q--) {
scanf("%d" , &n);
if(n == ) {
scanf("%d %s" , &x , c);
x--;
for(int i = ; i <= ; i++) {
if(s[x] == 'A') add( , i , x % i , x , -);
if(s[x] == 'T') add( , i , x % i , x , -);
if(s[x] == 'G') add( , i , x % i , x , -);
if(s[x] == 'C') add( , i , x % i , x , -);
}
for(int i = ; i <= ; i++) {
if(c[] == 'A') add( , i , x % i , x , );
if(c[] == 'T') add( , i , x % i , x , );
if(c[] == 'G') add( , i , x % i , x , );
if(c[] == 'C') add( , i , x % i , x , );
}
s[x] = c[];
}
else {
scanf("%d%d%s" , &l , &r , c);
l--, r--;
int len = strlen(c);
int ans = ;
for(int i = ; i < len ; i++) {
if(c[i] == 'A') ans += (getsum( , len , (i + l) % len , r) - (l == ? : getsum( , len , (i + l) % len , l - )));
if(c[i] == 'T') ans += (getsum( , len , (i + l) % len , r) - (l == ? : getsum( , len , (i + l) % len , l - )));
if(c[i] == 'G') ans += (getsum( , len , (i + l) % len , r) - (l == ? : getsum( , len , (i + l) % len , l - )));
if(c[i] == 'C') ans += (getsum( , len , (i + l) % len , r) - (l == ? : getsum( , len , (i + l) % len , l - )));
}
printf("%d\n" , ans);
}
}
return ;
}
codeforces E. DNA Evolution(树状数组)的更多相关文章
- 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 ...
- [Codeforces 1208D]Restore Permutation (树状数组)
[Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...
- Codeforces 650D - Zip-line(树状数组)
Codeforces 题目传送门 & 洛谷题目传送门 我怕不是个 nt--一开始忽略了"询问独立"这个条件--然后就一直在想有什么办法维护全局 LIS--心态爆炸 首先离散 ...
- Codeforces 1139F Dish Shopping 树状数组套平衡树 || 平衡树
Dish Shopping 将每个物品拆成p 和 s 再加上人排序. 然后问题就变成了, 对于一个线段(L - R), 问有多少个(li, ri)满足 L >= li && R ...
- Codeforces 830B - Cards Sorting 树状数组
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CodeForces 522D Closest Equals 树状数组
题意: 给出一个序列\(A\),有若干询问. 每次询问某个区间中值相等且距离最短的两个数,输出该距离,没有则输出-1. 分析: 令\(pre_i = max\{j| A_j = A_i, j < ...
- codeforces 589G G. Hiring(树状数组+二分)
题目链接: G. Hiring time limit per test 4 seconds memory limit per test 512 megabytes input standard inp ...
- CodeForces–830B--模拟,树状数组||线段树
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces 960F Pathwalks ( LIS && 树状数组 )
题意 : 给出若干个边,每条边按照给出的顺序编号,问你找到一条最长的边权以及边的编号同时严格升序的一条路径,要使得这条路径包含的边尽可能多,最后输出边的条数 分析 : 这题和 LIS 很相似,不同的 ...
- codeforces Gym100589H Count Subarrays 树状数组/线段树+离散化
题意:给你一个数组,问你有多少子数组中的逆元数不小于K个,N<105 还在研究中
随机推荐
- 常用GDB命令行调试命令
po po是print-object的简写,可用来打印所有NSObject对象.使用举例如下: (gdb) po self <LauncherViewController: 0x552c570& ...
- asp.net ashx处理程序中switch case的替代方案总结
目录 1.用委托字典代替switch...case; 2.利用反射替代switch...case: 3.比较两种方案 4.其他方案 4.说明 5.参考 在开发 asp.net 项目中,通常使用一般处理 ...
- C# Winform 自定义控件——竖着的Navbar
效果: 描述: 这是一个可折叠的菜单导航,主要是由panel.picturebox.label完成,界面的颜色用来区分一下各个组合控件,便于调试. 首先,首先是ImageButton: 这个是由Pic ...
- 【PYTHON】语法基础 | 开始使用Python
Python的热度不言而喻,机器学习.数据分析的首选语言都是Python,想要学习Python的小伙伴也很多,我之前也没有认真用过Python,所以也想体验一下它的魅力,索性花了两天集中看了一下它的基 ...
- Codeforces 436D Pudding Monsters
题意简述 开始有无限长的一段格子,有n个格子种有布丁怪兽,一开始连续的布丁怪兽算一个布丁怪兽. 每回合你可以将一个布丁怪兽向左或右移动,他会在碰到第一个布丁怪兽时停下,并与其合并. 有m个特殊格子,询 ...
- React中控制台警告
1.dll_lib.js:1 Warning: bind(): You are binding a component method to the component. React does this ...
- 帝国CMS(EmpireCMS) v7.5 前台XSS漏洞分析
帝国CMS(EmpireCMS) v7.5 前台XSS漏洞分析 一.漏洞描述 该漏洞是由于javascript获取url的参数,没有经过任何过滤,直接当作a标签和img标签的href属性和src属性输 ...
- [luogu4886] 快递员(点分治,树链剖分,lca)
dwq推的火题啊. 这题应该不算是点分治,但是用的点分治的思想. 每次找重心,算出每一对询问的答案找到答案最大值,考虑移动答案点,使得最大值减小. 由于这些点一定不能在u的两颗不同的子树里,否则你怎么 ...
- JVM调优实战:G1中的to-space exhausted问题
最近刚刚将自己的一个应用从CMS升级到G1,在一天早上,刚刚到办公室坐下,就收到手机一阵报警,去查看了监控,发现机器的内存出现了一个90度的涨幅,如下图所示: 在查看GC日志后,发现那个时间点附近出现 ...
- Yarn上常驻Spark-Streaming程序调优
对于长时间运行的Spark Streaming作业,一旦提交到YARN群集便需要永久运行,直到有意停止.任何中断都会引起严重的处理延迟,并可能导致数据丢失或重复.YARN和Apache Spark都不 ...