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

反正询问的长度只有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. highcharts 从后台动态改变数据

    //columnChart    图表对象,创建示例就展示了. var series = this.columnChart.series;                            whi ...

  2. Part2-HttpClient官方教程-Chapter7-高级主题(Advanced topics) (HTTP Caching)

    原文链接 7.1 自定义客户端连接 在某些情况下,为了能够处理非标准的.不兼容的行为,可能需要自定义HTTP消息通过网络传输的方式,而不是使用HTTP参数.例如,对于web爬虫,可能有必要迫使Http ...

  3. perl6 拖库脚本

    #注入点: #https://fei.sg/shop/products.php?action=content&id=-23 #check mysql column_name of the sq ...

  4. C基础 工程中常用的排序

    引言 - 从最简单的插入排序开始 很久很久以前, 也许都曾学过那些常用的排序算法. 那时候觉得计算机算法还是有点像数学. 可是脑海里常思考同类问题, 那有什么用呢(屌丝实践派对装逼学院派的深情鄙视). ...

  5. JDK1.8特性实现jdk动态代理,使业务解耦

    首先,先创建一个interface IHello 目标接口类 interface IHello { void sayHello(); } 然后再写一个目标类的实现类 class HelloImpl i ...

  6. FineReport——JS二次开发(CSS改变控件样式)

    FR提供一些选择器,可以改变部分控件的样式,那么对于如何书写自己的css: 可以自己写css文件导入,也可以在页面加载结束事件中添加JS方法来改变css样式. 以文本框为例: 书写css文件,保存至% ...

  7. POJ-2563

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10364   Accepted: 3842 D ...

  8. CountDownLatch源码浅析

    Cmd Markdown链接 CountDownLatch源码浅析 参考好文: JDK1.8源码分析之CountDownLatch(五) Java并发之CountDownLatch源码分析 Count ...

  9. addeventlistener监听scroll跟touch

    这三个事件只在手机上生效 touchstart,手指开始触屏 touchmove,手指移动 touchend,手指触屏结束   这个事件在手机上跟在pc端都生效 scroll事件     addeve ...

  10. Django Rest Framework用户访问频率限制

    一. REST framework的请求生命周期 基于rest-framework的请求处理,与常规的url配置不同,通常一个django的url请求对应一个视图函数,在使用rest-framewor ...