Codeforces Round #316 (Div. 2) C. Replacement
来源:互联网 发布:网络电影播放器 编辑:程序博客网 时间:2024/05/22 00:17
Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacementas 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 xi (1 ≤ xi ≤ n) of string s is assigned value ci. After each operation you have to calculate and output the value of f(s).
Help Daniel to process all queries.
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 xi and ci (1 ≤ xi ≤ n, ci — a lowercas English letter or a period sign), describing the query of assigning symbol ci to position 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.
10 3.b..bz....1 h3 c9 f
431
4 4.cc.2 .3 .2 a1 a
1311
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.")
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;char str[300010];int main(){int n,m;scanf("%d %d",&n,&m);scanf("%s",str);int ans=0;for(int i=0;i<n;i++){if(str[i]=='.'&&str[i+1]=='.') ans++;}int oper=0;char a;for(int i=0;i<m;i++){scanf("%d",&oper);getchar();scanf("%c",&a);oper--;if(str[oper]<='z'&&str[oper]>='a'&&a=='.'){if(str[oper-1]=='.') ans++;if(str[oper+1]=='.') ans++;str[oper]=a;}if(str[oper]=='.'&&a<='z'&&a>='a'){if(str[oper-1]=='.') ans--;if(str[oper+1]=='.') ans--;str[oper]=a;}printf("%d\n",ans);}return 0;}
- Codeforces Round #316 (Div. 2)-C. Replacement
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div.2) C. Replacement
- Codeforces Round #316 (Div. 2)570C Replacement(脑洞)
- 570C. Replacement Codeforces Round #316 (Div. 2)
- C. Replacement( Codeforces Round #316 (Div. 2) 模拟)
- Codeforces Round #316 (Div. 2) C. Replacement (模拟)
- C. Replacement-----(Codeforces Round #316 (Div. 2))
- Codeforces Round #316 (Div. 2) C. Replacement(线段树)
- Codeforces Round #316 (Div. 2) C. Replacement 找规律 或 线段树
- Codeforces Round #316 (Div. 2) C 模拟
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #316 (Div. 2)
- HDU 2563 统计问题 (DFS + 打表)
- 结构之美——优先队列三大结构(三)——Pairing Heap
- Visual studio 2013 批量删除空行的方式
- 黑马程序员———C语言———【枚举、typedef、宏、static和extern、文件操作】
- input文本框没有onchange事件,可以通过下面两种方法实现当input内容改变时触发事件
- Codeforces Round #316 (Div. 2) C. Replacement
- 关于Java多线程小结
- 枚举 - hdu5353 Average
- Lifecycle Controller update required DELL服务器 boot message
- 结构之美——优先队列基本结构(四)——二叉堆、d堆、左式堆、斜堆
- maven中把依赖的JAR包一起打包
- 手机APP
- cocoapods的使用
- 初识设计模式之装饰