Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E 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的更多相关文章
- 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. 1, rated, based on VK Cup Finals) C. DNA Evolution
题意跟某道我出的等差子序列求最值非常像…… 反正询问的长度只有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) 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 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) Problem C (Codeforces 828C) - 链表 - 并查集
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
随机推荐
- paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之全0/1/z/x的SV写法
- paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之output encoded style with registered outputs(Good style)
把输出跟状态编码结合起来,即使可以省面积又是寄存器输出.但是没有讲解如何实现这种高效的编码.
- Python语言程序设计之一--for循环中累加变量是否要清零
最近学到了Pyhton中循环这一章.之前也断断续续学过,但都只是到了函数这一章就停下来了,写过的代码虽然保存了下来,但是当时的思路和总结都没有记录下来,很可惜.这次我开通了博客,就是要把这些珍贵的学习 ...
- SQL前后端分页
/class Page<T> package com.neusoft.bean; import java.util.List; public class Page<T> { p ...
- try_except__异常处理
try...except.raise 一.try...except 有时候我们写程序的时候,会出现一些错误或异常,导致程序终止.例如,做除法时,除数为0,会引起一个ZeroDivisionError ...
- selenium2基本控件介绍及其代码
输入框:input 表现形式: 1.在html中一般为:<input id="user" type="text"> 主要操作: ...
- 令人惊叹的Chrome浏览器插件
Chrome是一个简洁而又高效(高性能,高消耗)的浏览器.接下来让我吐血推荐一些常用的Chrome插件. 日常插件 uBlock Origin ----- 比Adblock性能更高的广告插件. Adk ...
- Leetcode21--->Merge Two Sorted Lists(合并两个排序的单链表)
题目: 给出两个排序的单链表,合并两个单链表,返回合并后的结果: 解题思路: 解法还是很简单的,但是需要注意以下几点: 1. 如果两个链表都空,则返回null; 2. 如果链表1空,则返回链表2的 ...
- 80x86保护模式下IDT和中断调用过程分析
80x86保护模式下IDT和中断调用过程分析 1.中断描述符表(IDT),将每个异常或中断向量分别与它们的处理过程联系起来.与GDT和LDT类似,IDT也是由8字节长度的描述符组成.IDT空描述符的存 ...
- Leetcode 433.最小基因变化
最小基因变化 一条基因序列由一个带有8个字符的字符串表示,其中每个字符都属于 "A", "C", "G", "T"中的任 ...