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})$,略微有些暴力。

  1 #include <set>
  2 #include <cmath>
  3 #include <cstdio>
  4 #include <cstring>
  5 #include <iostream>
  6 #include <algorithm>
  7 using namespace std;
  8 const int LEN = 1e5 + 5;
  9 int i, j, k, n, m, s, t, ans, S, top;
 10 char c[LEN], a[LEN], d[LEN];
 11 int f[LEN][15][4];
 12 set <int> st;
 13 typedef set <int> :: iterator iter;
 14 const char to[4] = {‘A‘, ‘C‘, ‘G‘, ‘T‘};
 15 int get(char x) {
 16     if (x == ‘A‘) {
 17         return 0;
 18     } else if (x == ‘C‘) {
 19         return 1;
 20     } else if (x == ‘G‘) {
 21         return 2;
 22     } else {
 23         return 3;
 24     }
 25 }
 26 void init() {
 27     for (int i = n; i >= 1; i--) {
 28         for (int j = 1; j <= 10; j++) {
 29             for (int k = 0; k < 4; k++) {
 30                 if (get(c[i]) == k) {
 31                     f[i][j][k] = 1;
 32                 } else {
 33                     f[i][j][k] = 0;
 34                 }
 35                 if (i + j <= n) {
 36                     f[i][j][k] += f[i + j][j][k];
 37                 }
 38             }
 39         }
 40     }
 41 }
 42 int ask(int l, int r, int L) {
 43     int ans = 0;
 44     if (r - l + 1 <= L) {
 45         for (int i = l; i <= r; i++) {
 46             if (c[i] == a[i - l + 1]) {
 47                 ans++;
 48             }
 49         }
 50     } else {
 51         for (int i = 1; i <= L; i++) {
 52             int t = get(a[i]);
 53             ans += f[l + i - 1][L][t];
 54             int k = (r - l + 1 - i) / L + 1;
 55             if (k >= 0 && l + i - 1 + k * L <= n) {
 56                 ans -= f[l + i - 1 + k * L][L][t];
 57             }
 58         }
 59     }
 60     for (iter it = st.begin(); it != st.end(); it++) {
 61         int x = *it, t = get(d[x]);
 62         if (l <= x && x <= r) {
 63             int p = (x - l) % L + 1;
 64             if (get(c[x]) == get(a[p]) && get(a[p]) != t) {
 65                 ans--;
 66             }
 67             if (get(c[x]) != get(a[p]) && get(a[p]) == t) {
 68                 ans++;
 69             }
 70         }
 71     }
 72     return ans;
 73 }
 74 void rebuild() {
 75     for (iter p = st.begin(); p != st.end(); p++) {
 76         int x = *p;
 77         c[x] = d[x];
 78     }
 79     init();
 80     st.clear();
 81 }
 82 int main() {
 83     scanf("%s", c + 1);
 84     n =  strlen(c + 1);
 85     S = sqrt(n) + 200;
 86     init();
 87     scanf("%d", &m);
 88     while (m--) {
 89         int op, l, r;
 90         scanf("%d", &op);
 91         if (op == 2) {
 92             scanf("%d %d", &l, &r);
 93             scanf("%s", a + 1);
 94             int L = strlen(a + 1);
 95             printf("%d\n", ask(l, r, L));
 96         } else {
 97             scanf("%d %s", &l, a + 1);
 98             st.insert(l);
 99             d[l] = a[1];
100             if (st.size() >= S) {
101                 rebuild();
102             }
103         }
104     }
105     return 0;
106 }

原文地址:https://www.cnblogs.com/NineSwords/p/9221064.html

时间: 2024-11-09 00:11:22

Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)的相关文章

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 it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seate

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)D. High Load

题意:出n个点,其中k个叶子节点,问构造出的树最远的两个点最近是多少 思路:以一个点为中心,然后m个伸出,一层层扩散,(n-1)%m==k,如果k==0,即可以平分,长度就是2*(n-1)/m,如果取模为k==1,说明多出一个,+1,其他的话,就是最后一层补k个,但是最长的还是+2 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main(){ 5 int n,m; 6 cin>>n>>m; 7 int

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) B. Black Square

题意:问是否可以形成一个全黑正方形 思路:可以找出正方形的边,然后判断下这个矩阵是否容得下,n,m都比边短,比赛的时候写麻烦了,还去找了这个正方形究竟在哪个位置,这样的话得考虑很多情况,不如就边*边-黑子的总数 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=2e5+10; 5 char a[102][102]; 6 int main(){ 7 int n,m; 8 s

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction

题意:给出各个字符串出现的起始位置,问整个的字符串是什么,(字典序最小) 思路:开始写的是用set+优先队列存取每个位置出现的最长字符串,然后遍历,爆内存...爆...内...存...我们可以用并查集,已经确认的位置他们并在一起,指向后面第一个没有被确认的(看代码理解吧) 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=2e6+10; 4 5 int n,fa[N]; 6 char s[N],b[N]; 7 8 in

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E DNA Evolution

DNA Evolution 题目让我们联想到树状数组或者线段树,但是如果像普通那样子统计一段的和,空间会爆炸. 所以我们想怎样可以表示一段区间的字符串. 学习一发大佬的解法. 开一个C[10][10][4][n],就可以啦,第二维表示e的长度,第一维表示i%e的长度,第三维表示颜色,第四维求和了. 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5+5; 4 char s[maxn]; 5 map&l

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组

E. DNA Evolution time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)爆零记

昨晚一个瓜皮说今晚有cf,听说是晚间场,我瞅了一眼,娃,VK Cup,上分的好机会,看着比赛时间就有点心酸了,0:35,当时一直在纠结要不要打的问题,当时想着应该不难吧,要不打一下吧,要不还是看看题先,如果容易就打,难的话就不打了好的吧!于是就这样愉快的决定了.......cf日常延时10分钟,0:45,要不要去睡觉啊,干脆先睡一觉好了,然后又是忍不住诱惑在等待开始! 比赛一开始,瞅了一眼A,这不是一道水题嘛,直接敲啊,然后1分钟就搞定了,交了就过了,B题直接求边界点就好了,扫了一遍就过了,C题

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

D题fst了,生无可恋.第二场rated的CF,打得精神恍惚 A. Unimodal Array 题意:判断数列是否是单峰的. 像题意那样分为三个阶段随便判一判就好了 #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; int n,x[105],part=1; bool f=1; int main() { scanf(&quo

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is a