【树状数组】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 ...
随机推荐
- tornado 学习之GET POST方法 -- (转)
import torndb import tornado.web import tornado.ioloop from tornado.options import define,options,pa ...
- 使用BackgroundWorker
1,WPF应用程序为单线程模型(STAThread),所有UI控件都是主线程创建的,只有主线程能操作UI元素的显示. 2,其他工作线程要维护UI控件的显示,需调用主线程的Dispather,执行Inv ...
- FJOI游记(日记向 不定期更新)
emmmm说实话只是突发奇想开个blog记录记录自己的内心想法罢了.. 2017/12/22:刷了一周的计算几何..刷的死去活来..结果还是被D惨了...譬如都不会考,要考我都不会什么的...感觉内心 ...
- php中使用static方法
<?php class Char{ public static $number = 0; public static $name; function __construct($what){ se ...
- Django 1.10中文文档-第一个应用Part6-静态文件
本教程上接Part5 .前面已经建立一个网页投票应用并且测试通过,现在主要讲述如何添加样式表和图片. 除由服务器生成的HTML文件外,网页应用一般还需要提供其它必要的文件——比如图片.JavaScri ...
- linux系统下git使用
转载:http://www.cnblogs.com/bear2flymoon/p/4335364.html?ADUIN=563508762&ADSESSION=1430887070&A ...
- html5重力感应事件之DeviceMotionEvent
前言 今天主要介绍一下html5重力感应事件之DeviceMotionEvent,之前我的一篇文章http://www.haorooms.com/post/jquery_jGestures, 介绍了第 ...
- php上传文件限制
客户端限制(客户端限制在实际上是无法阻止上传): 通过表单隐藏域限制上传文件的最大值 <input type=’hidden’ name=’MAX_FILE_SIZE’ value=’字节数’ ...
- python字符编码与解码 unicode,str
解释以下几个问题: (1)python2中str和unicode是两种字符串类型,与字符编码方式是什么关系? (2)str和unicode是怎么相互转换的? (3)'\x...':'\u...', ' ...
- PHP给图片加水印具体实现
给图片加水印实现方法如下: class Mark { public function __construct() { } /** * 加水印 * @param file $srcImg 要加水印的图片 ...