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. fineReport---sql

    一.开窗函数-逐层平均 在创建数据集时用sql的开窗排名函数[AVG(字段) over(PARTITION BY 分组字段 order by 逐层字段)]处理,然后进行直接调用. 详细说明 二.开窗函 ...

  2. FineReport----报表模板入门教程1

    FineReport就一款类Excel操作界面的报表工具,通过拖拖拽拽简单实现报表制作,实现数据展示.数据查询.数据录入功能,并且支持图形多样化展示. 一.入门小例子 1. 打开设计器 启动FineR ...

  3. thinkphp,下载附件

    ThinkPHP框架下有个Org/Net/Http.class.php的方法download. Http.class.php的download方法如下 /** * 下载文件 * 可以指定下载显示的文件 ...

  4. Css选择器定位详解

    1.使用 class 属性来定位元素,方法如下: driver.findElement(By.cssSelector("input.login")); 即可以先指定一个 HTML的 ...

  5. 某游戏应用的redis 数据库结构设计(转)

    add by zhj: 搜了一下作者,原来之前是网易的大牛.2011年的文章,有些老了,很多地方可以将string类型键转为hash类型,这样更节省内存,将key聚合在一起,也更简练. 原文:http ...

  6. python逆向工程:通过代码生成类图

    python逆向工程:通过代码生成类图 大致过程 现在有一个core包,里面有python的代码. 通过core包,生成python的类图,如下: 实施步骤: 1.首先安装graphviz,一个画图工 ...

  7. Touch事件分发机制

    原文:http://www.cnblogs.com/linjzong/p/4191891.html Touch事件分发中只有两个主角:ViewGroup和View.Activity的Touch事件事实 ...

  8. 005-环境安装【docker、fabric】

    1.参考地址:https://hyperledger-fabric.readthedocs.io/en/latest/prereqs.html#install-curl 一.前置条件和系统配置 1.安 ...

  9. Java NIO2 File API介绍

    Introduction to the Java NIO2 File API GitHub NIO2中的文件API是Java 7附带的Java平台的主要新功能之一,特别是新的文件系统API的一个子集以 ...

  10. Python基础总结(字符串常用,数字类型转换,基本运算符与流程控制)

    一.字符串常用操作 #Python strip() 方法用于移除字符串头尾指定的字符(默认为空格) name='*egon**' print(name.strip('*'))#移除 name 变量对应 ...