Codeforces 828 E DNA Evolution(树状数组方法)
来源:互联网 发布:淘宝摄影店 编辑:程序博客网 时间:2024/05/22 06:20
题目地址:http://codeforces.com/contest/828/problem/E
题意:给你个DNA序列,有两个操作,一个是改变DNA序列里的一个碱基,另一个是查询l~r中有多少是和另一个序列(给出的序列不断重复形成的)碱基相同的,求出相同碱基的数量。
思路:因为操作的次数太多了,所以可以想到用树状数组去存,预处理好,那样查询就特别方便了,
TreeArray T[后面要查询的序列长度][在原序列的位置%序列长度(PS:把它化成一个一个的块)][碱基];
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#define LL long long #define N 100010#define M 50010#define inf 0x3f3f3f3fusing namespace std;const LL mod = 1e9 + 7;const double eps = 1e-9;struct TreeArray { int d[N]; void add(int x, int y) { while (x<N) { d[x] += y; x += x&-x; } } int get(int x) { int ans = 0; while (x) { ans += d[x]; x -= x&-x; } return ans; } int get(int l, int r) { return get(r) - get(l - 1); }}T[11][11][4];int solve(char s) { if (s == 'A') return 0; if (s == 'T') return 1; if (s == 'C') return 2; if (s == 'G') return 3;}int main() { cin.sync_with_stdio(false); int op, q, num, l, r; string str, s; while (cin >> str) { for (int i = 1; i <= 10; i++) { for (int j = 0; j < str.length(); j++) { T[i][(j + 1) % i][solve(str[j])].add(j + 1, 1); } } cin >> q; while (q--) { cin >> op; if (op == 1) { cin >> num >> s; for (int i = 1; i <= 10; i++) { T[i][num%i][solve(str[num - 1])].add(num, -1); T[i][num%i][solve(s[0])].add(num, 1); } str[num - 1] = s[0]; } else { cin >> l >> r >> s; int len = s.length(); int ans = 0; for (int i = 0; i < len; i++) { ans += T[len][(l + i) % len][solve(s[i])].get(l, r); } cout << ans << endl; } } } return 0;}
阅读全文
0 0
- Codeforces 828 E DNA Evolution(树状数组方法)
- Codeforces 827C/828E DNA Evolution[树状数组]
- Codeforces Round #423 E. DNA Evolution (树状数组)
- Codeforces Round #423 (Div. 2) E. DNA Evolution(树状数组)
- Codeforces 827C DNA Evolution(多维树状数组)
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 分组+树状数组
- codeforces 191 E (树状数组+二分)
- 树状数组(Garlands,codeforces 707e)
- Codeforces 217E Alien DNA (树状数组求第k大)
- Codeforces 276E(树状数组)
- Codeforces 387E 树状数组
- CodeForces 121E Lucky Array (树状数组)
- Codeforces 387E George and Cards(二分+树状数组)
- CodeForces 121E -- Lucky Array (树状数组)
- Codeforces Round #300(E,F 树状数组)
- CodeForces 628E Zbazi in Zeydabad(树状数组)
- codeforces-121E Lucky Array(树状数组)
- Codeforces Round #368 (Div. 2) E. Garlands (树状数组)
- servlet 生命周期(面试知识储备)
- Wireshark安装使用及报文分析(图文详解)
- JAVA深入研究——Method的Invoke方法。
- 【HTML5学习笔记】21:CSS盒模型 上
- Spring Boot Spring MVC Rest json输出日期的问题
- Codeforces 828 E DNA Evolution(树状数组方法)
- 动态规划问题中的几个经典问题代码
- Java多线程基础,线程的创建使用以及终止
- linux服务器开发三(网络编程)
- mysql的定时计划任务如何关闭
- 2017.07.12【NOIP提高组】模拟赛B组
- 获取系统信息之Packages.xml文件
- 高斯混合模型
- EXCEL导入