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. 【Python学习之五】高级特性2(切片、迭代、列表生成器、生成器、迭代器)

    2.迭代 如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration).在Python中,迭代是通过for ... in来完成的. ...

  2. python入门:输出1-10的所有数(自写)

    #!/usr/bin/env python # -*- coding:utf-8 -*- #输出1-10的所有数(自写) """ 导入time库,给kaishi赋值为数字 ...

  3. python入门:if和else的基本用法

    #!/usr/bin/env python # -*- coding:utf-8 -*- #2.X用raw_input,3.X用input #if和else的基本用法 name = input(&qu ...

  4. 初学Python02

    数据类型和变量: 1.整数  整数在Python中直接输入就好,没有特殊要求(正负整数皆可).由于计算机是二进制的,有时候会使用十六进制表示数字,0X+0-9或者a-f来表示. 2.浮点数   浮点数 ...

  5. poj:1985:Cow Marathon(求树的直径)

    Cow Marathon Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 5496   Accepted: 2685 Case ...

  6. acdsee 15中文版的许可证密钥+激活方法

    按以下方法就可以使用了,进入注册表的命令是:开始-运行-输入regedit   进入注册表后按下面的步骤操作就行. ACDSee15中文版激活英文版激活码5NR9CW-SSRMMY-KFWMQU-ZP ...

  7. iOS开发~CocoaPods安装和使用

    随着 iOS 开发者的增多,业界也出现了为 iOS 程序提供依赖管理的工具,它的名字叫做:CocoaPods. CocoaPods项目的源码 在 Github 上管理.该项目开始于 2011 年 8 ...

  8. bootstrap里的fileimput的小问题

    fileinput 是bootstrap 里面一个非常好的插件 于是我很开心的开始的使用了 $("#file_upload").fileinput({ uploadUrl: &qu ...

  9. GCC内嵌汇编一些限制字符串

    /******************/ “b”将输入变量放入ebx “c”将输入变量放入ecx “d”将输入变量放入edx “s”将输入变量放入esi “d”将输入变量放入edi “q”将输入变量放 ...

  10. FastText 介绍

    FastText 介绍 在面试百度的NLP工程师时,被问及常用的词向量表示学习方法有哪些,我说知道word2vec,然后大佬又问我知道FastText么... 这就很尴尬了,不会! 不同于word2v ...