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. memcached 系列2:memcached实例(转载)

    在上一篇文章,我们讲了,为什么要使用memched做为缓存服务器(没看的同学请点 这里).下面让我们以memcached-1.2.1-win32版本的服务组件(安装后是以一个windows服务做dae ...

  2. 安装TFS2008最终版(转载)

    一.安装操作系统:windows server 2003 + Sp2具体步骤: 1.安装windows server 2003时选用工作组(默认为workgroup).由于在工作组环境中部署,因此使用 ...

  3. 理解模板引擎Razor 的原理(转载)

    Razor是ASP.NET MVC 3中新加入的技术,以作为ASPX引擎的一个新的替代项.简洁的语法与.NET Framework 结合,广泛应用于ASP.NET MVC 项目.Razor Pad是一 ...

  4. linux基本命令(4)-8.Ubuntu-jdk+tomcat+eclipse软件包安装

    第一步 安装jdk su - root 切换成root用户 sudo -i 不需要密码直接切换成root 1.进入usr目录 cd /usr 2.在usr目录下建立java安装目录 mkdir jav ...

  5. c# 改变图片的大小(w,h)

    本文介绍获取网络上的图片将其大小尺寸改成自己想要的 /// <summary> /// 图片大小裁剪 /// </summary> /// <param name=&qu ...

  6. Web SQL数据库

    Web SQL数据库:它是一个独立的规范,引入了一组使用SQL操作客户端数据库的API. openDatabase方法:这个方法使用现有的数据库或者新建的数据库创建一个数据库对象.如果数据库存在,op ...

  7. Emag eht htiw Em Pleh(imitate)

    Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2901   Accepted:  ...

  8. 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(三)

    主题:Service与Activity交互通信 问题的引出:现在有个需求,如果我们有一个下载任务,下载时间耗时比较长,并且当下载完毕后,需要更新UI的内容,这时,service中的bindServic ...

  9. sql注入之你问我答小知识

    /*每日更新,珍惜少年时博客*/ 1.问:为啥order by 是排序.而在注入当中后面加的却不是字段而是数字捏? 答:第N个字段嘛.order by 5就是第五个字段,如果5存在,6不存在.就说明只 ...

  10. POJ 1251 Jungle Roads (prim)

    D - Jungle Roads Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Su ...