题意跟某道我出的等差子序列求最值非常像……

反正询问的长度只有10种,你就建立10批树状数组,每组的公差是确定的,首项不同。

然后询问的时候只需要枚举询问串的每一位,找找这一位对应哪棵树状数组即可。

修改的时候会在10棵树状数组里修改,也是算算修改的位置对应哪一棵即可。

要注意,一共有4种字符,每个树状数组其实分成4个,就只需要单点修改,维护前缀和了……

#include<cstdio>
#include<cstring>
using namespace std;
int n,m,ma[201];
char a[100010];
struct BIT{
int siz;
int* d;
void init(int siz){
this->siz=siz;
d=new int[siz];
memset(d,0,sizeof(int)*siz);
}
void Update(int p,int v){for(;p<siz;p+=(p&(-p))) d[p]+=v;}
int Query(int p){int res=0; for(;p;p-=(p&(-p))) res+=d[p]; return res;}
}T[11][11][4];
int main(){
ma['A']=0;
ma['T']=1;
ma['G']=2;
ma['C']=3;
scanf("%s%d",a+1,&m);
n=strlen(a+1);
for(int i=1;i<=10;++i){
for(int j=1;j<=i;++j){
for(int k=0;k<4;++k){
T[i][j][k].init(n/i+5);
}
for(int k=j,l=1;k<=n;k+=i,++l){
T[i][j][ma[a[k]]].Update(l,1);
}
}
}
int op,x,y,z;
char e[14];
for(;m;--m){
scanf("%d%d",&op,&x);
if(op==1){
scanf("%s",e);
for(int i=1;i<=10;++i){
int x1=x/i+(x%i!=0);
int x0=x-(x1-1)*i;
T[i][x0][ma[a[x]]].Update(x1,-1);
T[i][x0][ma[e[0]]].Update(x1,1);
}
a[x]=e[0];
}
else{
int ans=0;
scanf("%d%s",&y,e+1);
int len=strlen(e+1);
for(int i=1;i<=len;++i){
int X=x+i-1;
int X1=X/len+(X%len!=0);
int X0=X-(X1-1)*len;
// int tmp=X1 + (y-x+1)/len + ((y-x+1)%len>=i) - 1;
ans+=(T[len][X0][ma[e[i]]].Query(X1 + (y-x+1)/len + ((y-x+1)%len>=i) - 1) -
T[len][X0][ma[e[i]]].Query(X1-1));
}
printf("%d\n",ans);
}
}
return 0;
}

【树状数组】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) C. 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. 2, rated, based on VK Cup Finals) E DNA Evolution

    DNA Evolution 题目让我们联想到树状数组或者线段树,但是如果像普通那样子统计一段的和,空间会爆炸. 所以我们想怎样可以表示一段区间的字符串. 学习一发大佬的解法. 开一个C[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) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

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

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

  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. HTML/CSS/JS编码规范

    最近整理了一份HTML/CSS/JS编码规范,供大家参考.目录:一.HTML编码规范二.CSS编码规范三.JS编码规范 一.HTML编码规范 1. img标签要写alt属性 根据W3C标准,img标签 ...

  2. Centos7的iso everything与DVD以及Live的区别

    DVD.ISO 可以用安装程序安装的所有安装包,推荐镜像 Netinstall.iso 从网络安装或者救援系统 Everything.iso 包含centos7的一套完整的软件包,可以用来安装系统或者 ...

  3. Java的四种引用——强弱软虚

    1.强引用—用new 当我们用new向堆区申请一片内存空间时,此时就是强引用. 当内存不足,GC(垃圾收集器)不会回收该强引用的对象. 2.软引用—用SofeReference类实现 用来描述一些还有 ...

  4. 【DeepLearning学习笔记】Coursera课程《Neural Networks and Deep Learning》——Week2 Neural Networks Basics课堂笔记

    Coursera课程<Neural Networks and Deep Learning> deeplearning.ai Week2 Neural Networks Basics 2.1 ...

  5. mongodb 学习笔记--- 基础知识

    1.mongodb的安装 (1) mac使用brew 安装就好 brew install mongodb (2) mkdir /data/db 作为mongodb默认的数据目录 并 sudo chow ...

  6. 【bzoj4530】大融合(LCT的子树维护)

    LCT维护子树并没有想象中的那么难,在这里只是复习下. (其他的维护子树的题目,可见:“共价大爷游长沙”) 只要记录下虚边连接的信息就好了. #include<bits/stdc++.h> ...

  7. (转)关于bootstrap, boosting, bagging,Rand forest

    转自:https://blog.csdn.net/jlei_apple/article/details/8168856 这两天在看关于boosting算法时,看到一篇不错的文章讲bootstrap, ...

  8. 【LabVIEW技巧】LabVIEW中的错误2

    前言 通过上一个文章的介绍,我们发现LabVIEW自带的错误管理依旧比较基础,如果需要对错误进行很好的管理,则需要进一步的进行程序编写. 用于在程序设计的过程中,为了保证程序的健壮性,我们需要 1.忽 ...

  9. C++ 输入ctrl+z 不能再使用cin的问题

    问题介绍: 程序步骤是开始往容器里面写数据,以Ctrl+Z来终止输入流,然后需要输入一个数据,来判断容器中是否有这个数据. 源代码如下: #include<iostream> #inclu ...

  10. 数据库简述(以MySQL为例)

    一.数据库中的概念 1.数据库是用户存放数据.访问数据.操作数据的存储仓库,用户的各种数据被有组织地存放在数据库中.可以随时被有权限的用户查询.统计.添加.删除和修改.可以说,数据库是长期存储在计算机 ...