Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E DNA Evolution
题目让我们联想到树状数组或者线段树,但是如果像普通那样子统计一段的和,空间会爆炸。
所以我们想怎样可以表示一段区间的字符串。
学习一发大佬的解法。
开一个C[10][10][4][n],就可以啦,第二维表示e的长度,第一维表示i%e的长度,第三维表示颜色,第四维求和了。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+;
char s[maxn];
map<char,int> mp;
int C[][][][maxn];
int n = ;
void add(int a,int b,int c,int d,int x)
{
while(d<=n)
{
C[a][b][c][d] += x;
d += (d&-d);
}
}
int sum(int a,int b,int c,int d)
{
int res = ;
while(d>)
{
res += C[a][b][c][d];
d -= (d&-d);
}
return res;
}
int main()
{
mp['A'] = ;
mp['T'] = ;
mp['G'] = ;
mp['C'] = ;
cin>>(s+);
n = strlen(s+);
//cout<<(s+1)<<endl;
int q,l,r;
char e[];
for(int i=;i<=n;i++)
{
for(int j=;j<=;j++)
{
add((i-)%j,j,mp[s[i]],i,);
}
}
cin>>q;
while(q--)
{
int mark = ;
cin>>mark;
if(mark==)
{
cin>>r>>e;
for(int j=;j<=;j++)
{
add((r-)%j,j,mp[s[r]],r,-);
add((r-)%j,j,mp[e[]],r,);
}
s[r] = e[];
}
else
{
cin>>l>>r>>e;
int res = ;
int elen = strlen(e);
for(int i=;i<elen;i++)
{
// cout<<sum((l+i-1)%elen,elen,mp[e[i]],r)<<endl;
res += (sum((l+i-)%elen,elen,mp[e[i]],r)-sum((l+i-)%elen,elen,mp[e[i]],l-));
}
cout<<res<<endl;
}
}
return ;
}
/*
A
11
2 1 1 GCA
1 1 T
2 1 1 AACGACTG
2 1 1 GA
2 1 1 C
1 1 A
1 1 G
1 1 A
1 1 G
1 1 G
2 1 1 AG
*/
Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) 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 Round #423 (Div. 1, rated, based on VK Cup Finals) C. DNA Evolution
题意跟某道我出的等差子序列求最值非常像…… 反正询问的长度只有10种,你就建立10批树状数组,每组的公差是确定的,首项不同. 然后询问的时候只需要枚举询问串的每一位,找找这一位对应哪棵树状数组即可. ...
- Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)
Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A.String Reconstruction B. High Load C ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 828E) - 分块
Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) D. High Load 构造
D. High Load 题目连接: http://codeforces.com/contest/828/problem/D Description Arkady needs your help ag ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 并查集
C. String Reconstruction 题目连接: http://codeforces.com/contest/828/problem/C Description Ivan had stri ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) A,B,C
A.题目链接:http://codeforces.com/contest/828/problem/A 解题思路: 直接暴力模拟 #include<bits/stdc++.h> using ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
随机推荐
- 01将图片嵌入到Markdown文档中
将图片内嵌入Markdown文档中 将图片嵌入Markdown文档中一直是一个比较麻烦的事情.通常的做法是将图片存入本地某个路径或者网络存储空间,使用URL链接的形式插入图片: ![image][ur ...
- python爬虫基础09-selenium大全3/8-Remote Webdriver
Selenium笔记(3)Remote Webdriver 本文集链接:https://www.jianshu.com/nb/25338984 简介 selenium.webdriver.remote ...
- LeetCode(165) Compare Version Numbers
题目 Compare two version numbers version1 and version2. If version1 > version2 return 1, if version ...
- Mysql之数据库用户操作
查看用户: select host,user from mysql.user; //mysql库中user表,host为主机地址,user为用户名 mysql> select host,user ...
- POJ2239二分匹配
开始以为是最长路,想着把每一门课程的每一节课时作为一个点去建有向图...然后写的时候发现点太多了(300*7*12)建图特麻烦,就果断放弃了这个思路. 然后开始用排除法来想用什么算法合适,没环不可能缩 ...
- bzoj3262陌上花开 三维数点 cdq+树状数组
大早上的做了一道三维数点一道五位数点,神清气爽! 先给一维排序,变成一个奇怪的动态的二维数点(相当于有一个扫描面扫过去,导致一系列的加点和询问) 然后cdq分治,再变回静态,考虑前半段对后半段的影响 ...
- fhqtreap - Luogu 2464 [SDOI2008]郁闷的小J
[SDOI2008]郁闷的小JJ 题目描述 小J是国家图书馆的一位图书管理员,他的工作是管理一个巨大的书架.虽然他很能吃苦耐劳,但是由于这个书架十分巨大,所以他的工作效率总是很低,以致他面临着被解雇的 ...
- 淘宝的TProfile分析
TProfile是一个用来抓取性能数据的工具.大概是去年的时候对其分析了一下,并将它改造成了用于分析学习开源产品时的一个trace工具(不是很完善,自己用够用).现在将之前的笔记翻出来,记录一下. 1 ...
- spark作业
假定用户有某个周末网民网购停留时间的日志文本,基于某些业务要求,要求开发 Spark应用程序实现如下功能: 1.实时统计连续网购时间超过半个小时的女性网民信息. 2.周末两天的日志文件第一列为姓名,第 ...
- [python测试框架学习篇] 分享一个和adb相关的测试框架
https://testerhome.com/topics/7106 (user: zteandallwinner password: same to qq ) 264768502 · # ...