博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #316 (Div. 2) C. Replacement
阅读量:4982 次
发布时间:2019-06-12

本文共 3940 字,大约阅读时间需要 13 分钟。

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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 ≤ nci — a lowercas English letter or a period sign), describing the query of assigning symbol ci to position xi.

Output

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.

Sample test(s)
input
10 3.b..bz....1 h3 c9 f
output
431
input
4 4.cc.2 .3 .2 a1 a
output
1311
Note

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.")
我的思路是记录点所在的区域,用set记录下来,先算出第一次没有变化总共需要的操作数num,然后对于每一次变化,更改点的区间,变化操作数num。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define inf 0x7fffffff#define maxn 300060char s[maxn],str[10];struct node{ int l,r;}a,temp,b,temp1;bool operator<(node a,node b){ return a.l
myset;set
::iterator it;int main(){ int len,m,i,j,num,l,c,t; while(scanf("%d%d",&len,&m)!=EOF) { scanf("%s",s+1); myset.clear(); if(len==1){ for(i=1;i<=m;i++){ scanf("%d%s",&c,str); printf("0\n"); } continue; } num=0;i=1; while(i<=len){ if(s[i]=='.'){ a.l=i; while(s[i]=='.' && i<=len){ i++; } a.r=i-1; if(a.r-a.l+1>=2){ num+=a.r-a.l; } myset.insert(a); } else{ s[i]='a';i++; } } for(i=1;i<=m;i++){ scanf("%d%s",&c,&str); if(str[0]!='.'){ str[0]='a'; } if(str[0]==s[c]){ printf("%d\n",num);continue; } s[c]=str[0]; if(myset.empty()){ if(str[0]=='.'){ a.l=a.r=c; myset.insert(a); printf("0\n");continue; } else{ printf("0\n");continue; } } it=myset.begin(); if((*it).l>c ){ temp=*it; if(str[0]=='.'){ if(c+1==temp.l){ a.l=c;a.r=temp.r; num=num-(temp.r-temp.l)+a.r-a.l; printf("%d\n",num); myset.erase(temp); myset.insert(a); } else{ a.l=a.r=c; myset.insert(a); printf("%d\n",num); } } else{ printf("%d\n",num); } continue; } a.l=c;a.r=0; it=myset.upper_bound(a); it--; temp=*it; if(temp.r

转载于:https://www.cnblogs.com/herumw/p/9464667.html

你可能感兴趣的文章
在yii框架中如何连接数据库mongodb
查看>>
广播发送者与广播接收者
查看>>
只 能处理少于 32766 个字符的字符串
查看>>
表达式语言之EL表达式
查看>>
需求分析
查看>>
解决Win7下网络应用只有进程没有界面的问题
查看>>
半监督学习(一)
查看>>
[置顶] SPL讲解(6)--Condition篇
查看>>
在MyEclipse中配置Weblogic10服务器
查看>>
浙江大学PAT上机题解析之2-11. 两个有序链表序列的合并
查看>>
java中equals和==的区别详解
查看>>
数据类型(字符串)
查看>>
Something about Swing
查看>>
设计模式看了又忘,忘了又看?
查看>>
hdu4465 2012 Asia Chengdu Regional Contest 概率期望计算+对数放大/缩小幂指数+对数还原...
查看>>
安装magento主题模板
查看>>
JZOJ.4732 函数
查看>>
Linux:重命名
查看>>
Common Subsequence--poj1458(最长公共子序列)
查看>>
Sql Server2000分页存储过程
查看>>