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. ubuntu显示桌面的快捷键,以及修改方法

    在ubuntu下面,快速显示桌面,你可以这样做. 1,ctrl+alt+d (默认的) 2,alt+tab 可以切换到桌面 但是我想把它修改成和windows一样的,我该怎么做呢? 其实很简单. 系统 ...

  2. javascript单体模式

    单体模式的思想在于保证一个特定类仅有一个实例.这意味着当第二次使用同一个类创建的新对象的时候,应该得到与第一个所创建的对象完全相同. javacript中并没有类,因此对单体咬文嚼字的定义严格来说并没 ...

  3. Commando War

    Commando War“Waiting for orders we held in the wood, word from the front never cameBy evening the so ...

  4. 使用多种方式实现遍历HashMap

    今天讲解的主要是使用多种方式来实现遍历HashMap取出Key和value,首先在java中如果想让一个集合能够用for增强来实现迭代,那么此接口或类必须实现Iterable接口,那么Iterable ...

  5. The CompilerVersion constant identifies the internal version number of the Delphi compiler.

    http://delphi.wikia.com/wiki/CompilerVersion_Constant The CompilerVersion constant identifies the in ...

  6. Bmob用户管理操作

    注册用户 BmobUser bu = new BmobUser(); bu.setUsername("sendi"); bu.setPassword("123456&qu ...

  7. 【Hibernate】Hibernate系列4之配置文件详解

    映射文件详解 4.1.概述 4.2.主键生成策略 4.3.属性配置 准确映射: 4.4.映射组成关系 4.5.单向多对一映射 4.6.双向多对一关系 4.7.一对一关联关系-基于外键映射 一对一联合m ...

  8. JTA集成JOTM或Atomikos配置分布式事务(Tomcat应用服务器)

    一.以下介绍Spring中直接集成JOTM提供JTA事务管理.将JOTM集成到Tomcat中. (经过测试JOTM在批量持久化时有BUG需要修改源码GenericPool类解决)! 参考文章http: ...

  9. vs2013秘钥

    Ultimate:BWG7X-J98B3-W34RT-33B3R-JVYW9 Premium:FBJVC-3CMTX-D8DVP-RTQCT-92494  YKCW6-BPFPF-BT8C9-7DCT ...

  10. CSS用类选择器在本页写样式

    <title>静夜思</title><style type="text/css">p{color:#ff0000; font-size:24px ...