Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)
Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)
B. High Load
题意:给定一个只包含A,T,C,G的字符串S,有如下两种操作
1)修改一个点的字母.
2)给定一个字符串e ($\left | e \right |\leq 10$),生成一个由e重复组成的新串,eee...,问$S_{l..r}$中有几个字母跟这个新的字符串一一对应。
SOL:对于每个字母,用BIT[x][y][L]表示$S_{1..L}$中,所有$\equiv x\left (mod \, y \right )$的位置出现了该字母几次。然后复杂度大概就是$O(100*mlogn)$。
然而比赛的时候由于没有想到树状数组动态更新前缀和,而是用了一个静态数组,强行用定期重构过去了。。复杂度$O(10 * m*\sqrt{n})$,略微有些暴力。
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int LEN = 1e5 + ;
int i, j, k, n, m, s, t, ans, S, top;
char c[LEN], a[LEN], d[LEN];
int f[LEN][][];
set <int> st;
typedef set <int> :: iterator iter;
const char to[] = {'A', 'C', 'G', 'T'};
int get(char x) {
if (x == 'A') {
return ;
} else if (x == 'C') {
return ;
} else if (x == 'G') {
return ;
} else {
return ;
}
}
void init() {
for (int i = n; i >= ; i--) {
for (int j = ; j <= ; j++) {
for (int k = ; k < ; k++) {
if (get(c[i]) == k) {
f[i][j][k] = ;
} else {
f[i][j][k] = ;
}
if (i + j <= n) {
f[i][j][k] += f[i + j][j][k];
}
}
}
}
}
int ask(int l, int r, int L) {
int ans = ;
if (r - l + <= L) {
for (int i = l; i <= r; i++) {
if (c[i] == a[i - l + ]) {
ans++;
}
}
} else {
for (int i = ; i <= L; i++) {
int t = get(a[i]);
ans += f[l + i - ][L][t];
int k = (r - l + - i) / L + ;
if (k >= && l + i - + k * L <= n) {
ans -= f[l + i - + k * L][L][t];
}
}
}
for (iter it = st.begin(); it != st.end(); it++) {
int x = *it, t = get(d[x]);
if (l <= x && x <= r) {
int p = (x - l) % L + ;
if (get(c[x]) == get(a[p]) && get(a[p]) != t) {
ans--;
}
if (get(c[x]) != get(a[p]) && get(a[p]) == t) {
ans++;
}
}
}
return ans;
}
void rebuild() {
for (iter p = st.begin(); p != st.end(); p++) {
int x = *p;
c[x] = d[x];
}
init();
st.clear();
}
int main() {
scanf("%s", c + );
n = strlen(c + );
S = sqrt(n) + ;
init();
scanf("%d", &m);
while (m--) {
int op, l, r;
scanf("%d", &op);
if (op == ) {
scanf("%d %d", &l, &r);
scanf("%s", a + );
int L = strlen(a + );
printf("%d\n", ask(l, r, L));
} else {
scanf("%d %s", &l, a + );
st.insert(l);
d[l] = a[];
if (st.size() >= S) {
rebuild();
}
}
}
return ;
}
Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)的更多相关文章
- 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) 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 ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B
Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It i ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)
题目链接:http://codeforces.com/contest/828 A. Restaurant Tables time limit per test 1 second memory limi ...
随机推荐
- 制作简易app个人总结
1.每次修改app.js或者其他路由js文件,都必须重启node app.js,否则修改不起作用!!! 2.<link rel="stylesheet" href=" ...
- MySQL主从不一致修复
场景: 线上正在服务的库由于紧急主从切换导致主从不一致,报错信息如下: Last_Error: Coordinator stopped because there were error(s) in t ...
- 巨蟒python全栈开发-第18天 核能来袭-类和类之间的关系
一.今日主要内容: 1.类与类之间的关系 在我们的世界中事物和事物之间总会有一些联系. 在面向对象中,类和类之间也可以产生相关的关系 (1)依赖关系 执行某个动作(方法)的时候,需要xxx来帮助你完成 ...
- 用jq实现鼠标移入按钮背景渐变其他的背景效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- DRF(4) - 认证、权限组件
一.引入 通过前面三节课的学习,我们已经详细了解了DRF提供的几个重要的工具,DRF充分利用了面向对象编程的思想,对Django的View类进行了继承,并封装了其as_view方法和dispatch方 ...
- 同一TextView上内容的不同显示(最新)-SpannableString
上次发了一篇同一TextView内容的不同显示这篇文章. 有关颜色的不同显示,我使用了最简单可是也最复杂的方法.忘记使用SpannableString,现又一次发一下,大家參考下. TextView组 ...
- 七牛云 如何配置域名的 CNAME
CNAME 简介 CNAME 即指别名记录,也被称为规范名字.这种记录允你将多个名字映射到同一台计算机. 当需要将域名指向另一个域名,再由另一个域名提供 ip地址,就需要添加 CNAME 记录. 为什 ...
- tkprof工具详解二
TKPROF是一个可执行文件,自带在Oracle Server软件中,无需额外的安装. 该工具文件可以用来解析ORACLE的SQL TRACE(10046) 以便生成更可读的内容. 实际上tkp ...
- iOS学习之应用偏好设置
如今,即便是最简单的计算机程序也会包含一个偏好设置窗口,用户可以在其中设置应用专属的选项.在MAC OS X中,Preferences...菜单通常位于应用菜单中.选择该菜单项会弹出一个窗口,用户可以 ...
- MySQL 单表查询(Day42)
阅读目录 一,查询语法 二,简单查询 三,where约束 四,having过滤 五,分组查询 group by 六,关键字的执行优先级 七,查询排列 order by 八,使用聚合函数查询 九,whe ...