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学习之六】高阶函数1(map、reduce、filter、sorted)

    1.map map()函数接收两个参数,一个是函数,一个是Iterable,map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回.示例: >>> def ...

  2. NodeJS基础-Buffer

    Buffer用于处理二进制数据流 实例类似于整数数组,大小固定 C++代码在V8堆外分配物理内存 // 创建一个长度为10,且用0填充的Buffer const buf1 = Buffer.alloc ...

  3. python-numpy-pandas

    目录 numpy 模块 创建矩阵方法: 获取矩阵的行列数 切割矩阵 矩阵元素替换 矩阵的合并 通过函数创建矩阵 矩阵的运算 pandas模块 series (一维列表) DataFrame DataF ...

  4. HDU:2586-How far away

    How far away Time limit1000 ms Memory limit32768 kB Problem Description There are n houses in the vi ...

  5. Cinder配置多Ceph后端步骤

    1. 检查cinder当前backend配置 使用cinder service-list,查看cinder-volume服务的Host字段格式. 旧版格式: 新版格式: 旧版中Host字段是cinde ...

  6. UVa 10723 LCS变形 Cyborg Genes

    题解转自: UVA 10723 Cyborg Genes - Staginner - 博客园 首先这个题目肯定是按最长公共子序列的形式进行dp的,因为只有保证消去的一部分是最长公共子序列才能保证最后生 ...

  7. python - 字符串的格式化输出

    # -*- coding:utf-8 -*- '''@project: jiaxy@author: Jimmy@file: study_2_str.py@ide: PyCharm Community ...

  8. Python-函数参数的传递

    作者:Vamei 出处:http://www.cnblogs.com/vamei,感谢博主的分享, python的函数参数传递有这样的几种形式: 1.位置传递 2.关键字传递 3.参数默认值传递 4. ...

  9. 算法理论——Linear SVM

    问题引入 下面的三个超平面都起到分类的效果,哪个最好? 答案显然是第三个.为什么? 直觉上,如果现在我们有个测试点,非常靠近右下角的那个红叉叉,也就是说这个点的特征与那个红叉叉非常接近,这时候,我们希 ...

  10. JDBC 学习笔记(一)—— JDBC 基础

    1. 什么是 JDBC JDBC,Java Database Connectivity(Java 数据库连接),是一组执行 SQL 语句的 Java API. JDBC,是 Java SE(Java ...