C. Replacement

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/570/problem/C

Description

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 Input

10 3
.b..bz....
1 h
3 c
9 f

Sample Output

4
3
1

HINT

题意

给你一个字符串,然后每两个点可以变成一个点

然后有m次修改操作,每次可以修改一个位置的字符

然后问你修改之后,需要多少次操作,把所有的点,都变成连续的一个点

题解

出去玩了5天一回来,本不该做比赛的:(

set乱搞

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include<bits/stdc++.h>
#include <stack>
typedef long long ll;
using namespace std;
#define inf 10000000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//***************************************************************
set<int >s;
set<int >::iterator it,itt;
int vis[]; char a[];
int main()
{ int n=read();
int m=read();
gets(a+);
s.insert();
s.insert(n+);
int last=;
int r=;
int ans=;
for(int i=;i<=n;i++){
if(a[i]!='.'){
s.insert(i);
vis[i]=;
if(r>last)
ans+=(r-last-);
last=i;
r=i;
}
else {r++;
if(i==n){
if(r>last)
ans+=(r-last-);
}
}
// cout<<ans<<" "<<endl;
} //cout<<ans<<endl;
int x,l,mid;
char ch;
for(int i=;i<=m;i++){
scanf("%d %c",&x,&ch);
if(ch!='.')
{
if(vis[x]){
printf("%d\n",ans);
continue;
}
r=*s.lower_bound(x);
l=*--s.lower_bound(x);
// if(i==3){cout<<l<<" "<<r<<endl;}
ans-=(max(r-l-,));
//if(i==3)cout<<ans<<" ";
ans+=max(x-l-,);
// if(i==3)cout<<ans<<" ";
ans+=max(r-x--,);
// if(i==3)cout<<ans<<" ";
vis[x]=;
s.insert(x);
cout<<ans<<endl;
}
else {
if(s.count(x)==){
cout<<ans<<endl;
continue;
}
it=s.lower_bound(x);
mid=*it;
l=*--it;
it++;
r=*++it;
ans-=max(mid-l-,);
ans-=max(r-mid-,);
ans+=max(r-l-,);
vis[x]=;
s.erase(x);
cout<<ans<<endl;
}
}
return ;
}

好特么捉急

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include<bits/stdc++.h>
#include <stack>
typedef long long ll;
using namespace std;
#define inf 10000000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//***************************************************************
int n,m,x;
char c,ss[];
int main()
{
while(~scanf("%d%d",&n,&m))
{
int ans=;
scanf("%s",ss+);
for(int i=;i<=n;i++)
{
if(ss[i]=='.'&&ss[i+]=='.')
{
ans++;
}
}
for(int i=;i<=m;i++)
{
scanf("%d %c",&x,&c);
if(c=='.'&&ss[x]!='.')
{
if(ss[x-]=='.') ans++;
if(ss[x+]=='.') ans++;
}
if(c!='.'&&ss[x]=='.')
{
if(ss[x-]=='.') ans--;
if(ss[x+]=='.') ans--;
}
ss[x]=c;
printf("%d\n",ans);
}
}
return ;
}

Codeforces Codeforces Round #316 (Div. 2) C. Replacement set的更多相关文章

  1. Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树

    C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...

  2. Codeforces Round #316 (Div. 2) C. Replacement

    题意:给定一个字符串,里面有各种小写字母和' . ' ,无论是什么字母,都是一样的,假设遇到' . . ' ,就要合并成一个' .',有m个询问,每次都在字符串某个位置上将原来的字符改成题目给的字符, ...

  3. Codeforces Round #316 (Div. 2) C. Replacement(线段树)

    C. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #316 (Div. 2C) 570C Replacement

    题目:Click here 题意:看一下题目下面的Note就会明白的. 分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用. 直接判断: #include <bits/stdc++. ...

  5. Codeforces Round #316 (Div. 2) C Replacement 扫描法

    先扫描一遍得到每个位置向后连续的'.'的长度,包含自身,然后在扫一遍求出初始的合并次数. 对于询问,只要对应位置判断一下是不是'.',以及周围的情况. #include<bits/stdc++. ...

  6. Codeforces Beta Round #97 (Div. 1) A. Replacement 水题

    A. Replacement 题目连接: http://codeforces.com/contest/135/problem/A Description Little Petya very much ...

  7. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  8. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

随机推荐

  1. 使用 GDB 调试多进程程序

    使用 GDB 调试多进程程序 GDB 是 linux 系统上常用的调试工具,本文介绍了使用 GDB 调试多进程程序的几种方法,并对各种方法进行比较. 3 评论 田 强 (tianq@cn.ibm.co ...

  2. smarty 操作符号,大于、小于。。。

    eq相等,6 w% x7 w6 |3 _ne.neq不相等,( i" }" ~( `# V( t& C, k; [gt大于,lt小于,gte.ge大于等于,lte.le 小 ...

  3. (11)UI布局和分辨率适配

    一.Cocos编辑器 自动布局系统主要涉及固定与拉伸属性:   如图,总共可以修改控件的上下左右四个图钉和中间的两个拉伸条六个属性. 效果   1.当打开其中的任意一个图钉时,当前节点与父节点的对应边 ...

  4. 黑色30s高并发IIS设置

    在这篇博文中,我们抛开对阿里云的怀疑,完全从ASP.NET的角度进行分析,看能不能找到针对问题现象的更合理的解释. “黑色30秒”问题现象的主要特征是:排队的请求(Requests Queued)突增 ...

  5. [置顶] Android应用开发之版本更新你莫愁

    传送门 ☞ 轮子的专栏 ☞ 转载请注明 ☞ http://blog.csdn.net/leverage_1229 今天我们学习如何实现Android应用的自动更新版本功能,这是在各种语言编写的应用中都 ...

  6. iOS6.1完美越狱工具evasi0n1.3下载

    原地址:http://blog.sina.com.cn/s/blog_55f899fb0102ei49.html 标签: it 分类: MAC_OS_X evad3rs梦之队发布iOS6.1完美越狱工 ...

  7. spring无法扫描jar包的问题

    在日常开发中往往会对公共的模块打包发布,然后调用公共包的内容.然而,最近对公司的公共模块进行整理发布后.spring却无法扫描到相应的bean.折腾了好久,最终发现是认识上的误区. 2015-11-1 ...

  8. Android measure和layout的一点理解

    首先,推荐文章,http://blog.csdn.net/hqdoremi/article/details/9980481,http://www.docin.com/p-571954086.html ...

  9. 安装tar.bz2文件

    (1) 解包 – tar jxvf softname-10.0.1.tar.gz -C /usr/src/(-C指的是把文件解压到后面的路径下,此处可以不选) – cd /usr/src/softna ...

  10. IE的安全性设定增加“我的电脑”的安全性设定

    HKEY_CURRE-NT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Zones\,在右边窗口中找到DWORD值“ ...