CF570C.Replacement
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string s, of all occurrences of the substring let's choose the first one, and replace this substring with string ".". In other words, during the replacement operation, the first two consecutive periods are replaced by one. If string s contains no two consecutive periods, then nothing happens.
Let's define f(s) as the minimum number of operations of replacement to perform, so that the string does not have any two consecutive periods left.
You need to process m queries, the i-th results in that the character at position x__i (1 ≤ x__i ≤ n) of string s is assigned value c__i. After each operation you have to calculate and output the value of f(s).
Help Daniel to process all queries.
Daniel 有一个字符串 s,由小写英文字母和句点符号(字符 '.')组成。我们定义“替换操作”为以下步骤序列:在字符串 s 中找出子串 ".."(两个连续的句点),在所有该子串的出现位置中选择最靠前的一个,并将该子串替换为字符串 "."。换言之,在每次替换操作中,最靠前的两个连续句点被替换为一个句点。若字符串 s 中不存在两个连续的句点,则该操作不发生任何变化。
我们定义 f(s) 为使字符串中不再含有任何两个连续句点所需的最小替换操作次数。
你需要处理 m 个查询;第 i 个查询会将字符串 s 中位置 xi(1≤xi≤n)处的字符修改为字符 ci。每次修改后,你都需要计算并输出 f(s) 的值。
请帮助 Daniel 处理全部查询。
输入格式
The first line contains two integers n and m (1 ≤ n, m ≤ 300 000) the length of the string and the number of queries.
The second line contains string s, consisting of n lowercase English letters and period signs.
The following m lines contain the descriptions of queries. The i-th line contains integer x__i and c__i (1 ≤ x__i ≤ n, c__i — a lowercas English letter or a period sign), describing the query of assigning symbol c__i to position x__i.
第一行包含两个整数 n 和 m(1≤n,m≤300000),分别表示字符串的长度和查询次数。
第二行包含字符串 s,由 n 个小写英文字母和句点符号(.)组成。
接下来的 m 行描述各次查询。第 i 行包含一个整数 xi 和一个字符 ci(1≤xi≤n,ci 为一个小写英文字母或句点符号),表示将字符 ci 赋值给位置 xi 的查询。
输出格式
Print m numbers, one per line, the i-th of these numbers must be equal to the value of f(s) after performing the i-th assignment.
输出 m 个数字,每个数字占一行;其中第 i 个数字必须等于执行第 i 次赋值操作后 f(s) 的值。
输入输出样例
输入#1
10 3 .b..bz.... 1 h 3 c 9 f
输出#1
4 3 1
输入#2
4 4 .cc. 2 . 3 . 2 a 1 a
输出#2
1 3 1 1
说明/提示
Note to the first sample test (replaced periods are enclosed in square brackets).
The original string is ".b..bz....".
- after the first query f(hb..bz....) = 4 ("hb[..]bz...." → "hb.bz[..].." → "hb.bz[..]." → "hb.bz[..]" → "hb.bz.")
- after the second query f(hbс.bz....) = 3 ("hbс.bz[..].." → "hbс.bz[..]." → "hbс.bz[..]" → "hbс.bz.")
- after the third query f(hbс.bz..f.) = 1 ("hbс.bz[..]f." → "hbс.bz.f.")
Note to the second sample test.
The original string is ".cc.".
- after the first query: f(..c.) = 1 ("[..]c." → ".c.")
- after the second query: f(....) = 3 ("[..].." → "[..]." → "[..]" → ".")
- after the third query: f(.a..) = 1 (".a[..]" → ".a.")
- after the fourth query: f(aa..) = 1 ("aa[..]" → "aa.")
第一个样例测试的说明(被替换的句点用方括号标出)。
原始字符串为 .b..bz....。
- 第一次查询后,f(hb..bz....) = 4(
hb[..]bz....→hb.bz[..]..→hb.bz[..].→hb.bz[..]→hb.bz.); - 第二次查询后,f(hbс.bz....) = 3(
hbс.bz[..]..→hbс.bz[..].→hbс.bz[..]→hbс.bz.); - 第三次查询后,f(hbс.bz..f.) = 1(
hbс.bz[..]f.→hbс.bz.f.)。
第二个样例测试的说明。
原始字符串为 .cc.。
- 第一次查询后:f(..c.) = 1(
[..]c.→.c.); - 第二次查询后:f(....) = 3(
[..]..→[..].→[..]→.); - 第三次查询后:f(.a..) = 1(
.a[..]→.a.); - 第四次查询后:f(aa..) = 1(
aa[..]→aa.)。
输入解题思路,AI测评打分。不知道怎么写?