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的更多相关文章

  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 Round #423 (Div. 1, rated, based on VK Cup Finals) C. DNA Evolution

    题意跟某道我出的等差子序列求最值非常像…… 反正询问的长度只有10种,你就建立10批树状数组,每组的公差是确定的,首项不同. 然后询问的时候只需要枚举询问串的每一位,找找这一位对应哪棵树状数组即可. ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. sphinx 快速使用

    建立配置文件 例可以参照之前的模板新建一个配置文件 sphinx/etc目录 #MySQL数据源配置,详情请查看:http://www.coreseek.cn/products-install/mys ...

  2. Spring AOP注解形式简单实现

    实现步骤: 1:导入类扫描的注解解析器 命名空间:xmlns:context="http://www.springframework.org/schema/context" xsi ...

  3. centos7安装pgsql及操作命令

    1.下载所需要的数据库版本https://yum.postgresql.org/repopackages.php 2.安装数据库版本包 yum install -y https://download. ...

  4. STM32CUBEMX入门学习笔记1:软件的简单介绍

    STM32CUBEMX是ST公司设计的一款免费软件,软件可以通过其官网下载.现在已经下载到.通过STM32CUBEMX可以完成从单片机选型,程序初始化,中断配置……工作.并生成对应的"HAL ...

  5. gcc——预处理(预编译),编译,汇编,链接

    一,预编译 操作步骤:gcc -E hello.c -o hello.i 主要作用: 处理关于 “#” 的指令 [1]删除#define,展开所有宏定义.例#define portnumber 333 ...

  6. kettle-单表增量同步

    目标:利于kettle实现单表增量同步,以时间为判断条件 背景:源表:db1.q1 (2w条数据) 目标表:db2.q2(0条数据) 表结构: CREATE TABLE `q1` (  `ID` bi ...

  7. TTL与COMS的区别

    1.电平的上限和下限定义不一样,CMOS具有更大的抗噪区域. 同是5伏供电的话,ttl一般是1.7V和3.5V的样子,CMOS一般是  2.2V,2.9V的样子,不准确,仅供参考. 2.电流驱动能力不 ...

  8. 解决使用intellij idea开发MAVEN项目在target目录下不存在mapper.xml文件

    原 解决使用intellij idea开发MAVEN项目在target目录下不存在mapper.xml文件 原文章链接:https://blog.csdn.net/beauxie/article/de ...

  9. 软件工程师应该关注的web加密手段

    加密算法 1.非对称加密(公开密钥加密)       公开密钥加密,是加密和解密使用不同密钥的算法,广泛用于信息传输中. 常见的算法有:RSA.ElGamal.Rabin. 2.对称加密       ...

  10. Selenium WebDriver- 隐式等待

    隐式等待是只要有一个元素在设置的时间内没有找到,就会报超时 隐式等待是一个全局的设置,只要放在找东西语句的前面,它后面的找东西的语句都会默认等待设置的时间(这里是10秒),这是死等,除非立刻找到了,5 ...