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. docker在团队中的实践 How To Install Docker In CentOS

    " 预发布机器(centos-6.5),给每个同学都开通了ssh这个机器是大家一起共用的,稍后导些数据下来.后续 项目上线,产品测试,都是在这上面进行.  目前在一个物理机 " 3 ...

  2. YARN - Yet Another Resource Negotiator

    http://www.socc2013.org/home/program http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-ya ...

  3. Java 语言基础(一)

    大多数编程语言都包括以下基本内容: 关键字 标识符 注释 常量和变量 运算符 语句 函数 数组 学习语言最重要的两点: 该语言基础的表现形式是什么 这些东西什么时候使用 关键字 在程序语言中有特殊含义 ...

  4. PyQuery的基本使用详解

    0.安装:pip3 install pyquery 1.初始化 1.字符串初始化 # 字符串初始化 html = """ <div> <ul> & ...

  5. Android系统移植与调试之------->如何添加一个adb wifi无线调试的功能【开发者选项】-【Wifi调试】

    首先弄懂怎么设置adb wifi无线调试的功能,如下所示. 1. 手机端开启adb tcp连接端口 :/$setprop service.adb.tcp.port :/$stop adbd :/$st ...

  6. RT-Thread内核之线程调度(三)

    4.RT-Thread中的线程? /**  * 线程结构  */ struct rt_thread {     /** Object对象 */     char        name[RT_NAME ...

  7. idea导入项目出现Unable to import maven project: See logs for details提示(转载)

    摘要: 从git上面check多工程项目后,maven不能正常下载相应的依赖,最后查询国外网站,找出错误原因.按照此步骤,可以自动配置好每个工程的module. 删除项目根目录下.idea文件夹 关闭 ...

  8. appium API java

    原创内容,未经允许,禁止转载! driver.close();//关闭 driver.closeApp();//关闭应用,其实就是按home键把应用置于后台 driver.currentActivit ...

  9. java线程小结1

    1.创建线程的两种方法 新线程的创建和启动都是通过java代码触发的.除了第一个线程(也就是启动程序的.运行main()方法的线程)是由java平台直接创建的之外,其余的线程都是在java代码中通过“ ...

  10. cdoj1324卿学姐与公主

    地址:http://acm.uestc.edu.cn/#/problem/show/1324 卿学姐与公主 Time Limit: 2000/1000MS (Java/Others)     Memo ...