Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)

A.String Reconstruction

B. High Load

C. DNA Evolution

题意:给定一个只包含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)的更多相关文章

  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) Problem E (Codeforces 828E) - 分块

    Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  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) Problem C (Codeforces 828C) - 链表 - 并查集

    Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Python IDLE或shell中切换路径

    在Python自带的编辑器IDLE中或者python shell中不能使用cd命令,那么跳到目标路径呢.方法是使用os包下的相关函数实现路径切换功能. import os  os.getcwd() # ...

  2. delphi xe-system.json

    Delphi XE10有一个对JSON处理的单元,在你需要使用JSON的单元里面引入"System.json",随后你就可以用Delphi自己的json处理类了. 普通解析 实例1 ...

  3. Making training mini-batches

    Here is where we'll make our mini-batches for training. Remember that we want our batches to be mult ...

  4. ZooKeeper 基本介绍

    Zookeeper 作为一个分布式的服务框架,主要用来解决分布式集群中应用系统的一致性问题,它能提供基于类似于文件系统的目录节点树方式的数据存储, Zookeeper 作用主要是用来维护和监控存储的数 ...

  5. 6.javaScript中的二维数组

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. 一篇搞定Vuex

    1.简介 首先,你必须明显明白vuex到底是干啥的,主要解决开发中的哪些问题? Vuex是一个专门为Vue.js应用程序开发的状态管理模式,它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证 ...

  7. pandas 如何判断指定列是否(全部)为NaN(空值)

    判断某列是否有NaN df['$open'].isnull().any() # 判断open这一列列是否有 NaN 判断某列是否全部为NaN df['$open'].isnull().all() # ...

  8. rest_framework 响应器

    一 作用 根据 用户请求URL 或 用户可接受的类型,筛选出合适的 渲染组件.用户请求URL:    http://127.0.0.1:8000/test/?format=json    http:/ ...

  9. 安装SQL2012

    1. 优先安装软件 1. net framework3.5. 2. 在安装SQL SERVER 2012前需要3.5的支持.在WIN 2012系统可以在系统管理的添加角色和功能中安装,如下将[.NET ...

  10. R 入门笔记

    PS:初学R  为了查阅方便 借鉴的网友的博客和自己的总结记录一下 http://blog.csdn.net/jack237/article/details/8210598 命令简介 R对大小写是敏感 ...