【树状数组】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) C. DNA Evolution
题意跟某道我出的等差子序列求最值非常像……
反正询问的长度只有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的更多相关文章
- 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. 2, rated, based on VK Cup Finals) E DNA Evolution
DNA Evolution 题目让我们联想到树状数组或者线段树,但是如果像普通那样子统计一段的和,空间会爆炸. 所以我们想怎样可以表示一段区间的字符串. 学习一发大佬的解法. 开一个C[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) 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) 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 C (Codeforces 828C) - 链表 - 并查集
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
随机推荐
- poj 2762 tarjan缩点+拓扑序
2013-09-08 10:00 var m, n :longint; t :longint; f, last :..] of longint; pre, other :..] of longint; ...
- ”未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项
引用:http://www.cnblogs.com/joey0210/archive/2012/09/29/2708420.html 上一篇文章说到了DLL引用问题,主要是说的程序中如果使用过了反射, ...
- Linux实际用户(组)ID,有效用户(组)ID,设置用户(组)ID
实际用户(组)ID: 标识用户是谁,这两个字段在登录时取自口令文件中的登录项. 有效用户(组)ID: 决定了对文件的访问权限,通常有效用户(组)ID等于实际用户(组)ID,谁运行有效ID就等于谁的实际 ...
- 下载 LFS所需要的源码包的脚本程序及检验方法
下载 LFS所需要的源码包的脚本程序及检验方法 http://blog.csdn.net/yygydjkthh/article/details/45315143
- HTML5API(4)
十三.服务器推送 服务器主动向客户端推送信息 传统的HTTP协议传输,服务器是被动相应客户端的请求 1.解决方案 ajax轮询.ajax长轮询 Server-Send-Event WebSocket ...
- windows访问linux共享文件夹
1.windows的网上邻居,是通过smb协议来共享信息的,如果需要给访问linux上的共享目录被windows访问到,需要linux有smb协议 sudo apt-get install samba ...
- 使用 Visual Studio 部署 .NET Core 应用 ——.Net Core 部署到SUSE Linux Enterprise Server 12 SP2 64 位(GNOME 版本3.20.2)
SUSE Linux安装 apache 命令:sudo zypper in apache 设置apache 服务可用 命令:sudo systemctl enable apache2.service启 ...
- MyBatis3-与Spring 4集成
继续使用前一篇的例子http://www.cnblogs.com/EasonJim/p/7052368.html,实际项目中,通常会用Spring来管理DataSource等.充分利用Spring基于 ...
- jenkins构建触发器定时任务Build periodically和Poll SCM【转载】
转至博客:上海-悠悠 前言 跑自动化用例每次用手工点击jenkins出发自动化用例太麻烦了,我们希望能每天固定时间跑,这样就不用管了,坐等收测试报告结果就行. 一.定时构建语法 * * * * * ( ...
- [译]怎样用HTML5 Canvas制作一个简单的游戏
这是我翻译自LostDecadeGames主页的一篇文章,原文地址:How To Make A Simple HTML5 Canvas Game. 下面是正文: 自从我制作了一些HTML5游戏(例如C ...