先扫描一遍得到每个位置向后连续的'.'的长度,包含自身,然后在扫一遍求出初始的合并次数。

对于询问,只要对应位置判断一下是不是'.',以及周围的情况。

#include<bits/stdc++.h>
using namespace std; const int maxn = 3e5+;
char s[maxn];
int post[maxn]; int main()
{
//freopen("in.txt","r",stdin);
int n,m; scanf("%d%d",&n,&m); //getchar();
scanf("%s",s);
post[n-] = s[n-] == '.';
for(int i = n-; i >= ; i--){
if(s[i] == '.'){
post[i] = post[i+]+;
}
}
int cnt = ;
for(int i = ; i < n; i++){
if(s[i] == '.'){
cnt += post[i]-;
i += post[i];
}
}
char ch[];
while(m--){
int i;
scanf("%d%s",&i,ch); i--;
if(ch[] == '.'){
if(s[i] == '.'){
printf("%d\n",cnt);
}else {
bool f1 = i> && s[i-] == '.';
bool f2 = i+<n && s[i+] == '.';
cnt += f1+f2;
printf("%d\n",cnt);
}
}else {
if(s[i] == '.'){
bool f1 = i> && s[i-] == '.';
bool f2 = i+<n && s[i+] == '.';
cnt -= f1+f2;
printf("%d\n",cnt);
}else {
printf("%d\n",cnt);
}
}
s[i] = ch[];
}
return ;
}

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

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

    C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/proble ...

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

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

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

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

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

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

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

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

  6. Codeforces Round #316 (Div. 2)

    A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. Codeforces Round #316 (Div. 2) C 思路/模拟

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

  8. Codeforces Round #316 (Div. 2) (ABC题)

    A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...

  9. Codeforces Round #316 (Div. 2) B. Simple Game

    思路:把n分成[1,n/2],[n/2+1,n],假设m在左区间.a=m+1,假设m在右区间,a=m-1.可是我居然忘了处理1,1这个特殊数据.被人hack了. 总结:下次一定要注意了,提交前一定要看 ...

随机推荐

  1. PXE与cobbler实现系统自动安装

    安装操作系统的流程事实上并不复杂,如果你要给三五台服务器安装系统那么我们手工去安装即可.但是当我们要部署的是大型机房的操作系统的时候显然手动安装去一台一台的点,是不现实的.尤其现在互联网行业高速发展, ...

  2. sfc命令

    开始—>运行—>再输入“sfc /scannow”(不含引号),“sfc”是“系统文件检测”程序,它是一个在命令提示符下使用的实用程序,只有是管理员才能使用该程序,这个程序的作用就是检测系 ...

  3. SQL——基础概念

    服务器登录名:指有权限登录到某服务器的用户:如sa 服务器角色:指一组固定的服务器用户,默认有9组: 登录名一定属于某些角色,默认为public 服务器角色不容许更改 登录后也不一定有权限操作数据库 ...

  4. 细说CSS中的display属性

    相信大部分奋战在前端的,尤其在前端攻城的过程中,有一种越陷越深的感觉,不错,一如前端深似海,从此妹子是浮云啊,前端上手容易,深入难啊!下面我就CSS中的display属性讲下我自己所积累的,与大家共享 ...

  5. HDU2222【AC自动机(基础·模板)】

    Frist AC zi dong ji(Aho-Corasick Automation) of life #include <bits/stdc++.h> using namespace ...

  6. Unity3D 图形优化

    Unity3D 图形优化 例如DrawCall,我得到的是一些并不完全正确的信息,例如将N个纹理打包成一个图集,这个图集就只会产生一个DrawCall,如果不打成图集,那么就会有N个DrawCall. ...

  7. fetch请求数据,后台将cookie一起返回时

    请求时,添加以上标记的属性,就可以拿到后台给的cookie,并返回给后台.比如登录后才能有的操作,这样就需要返回给后台cookie从而判断是否登录

  8. 页面嵌套时js失效解决方法

    事件:iframe或easyui的dialog嵌套页面时,被嵌套的页面可能js因位置失效; 解决: //动态加载js(根据父级html位置计算) jQuery.getScript("scri ...

  9. Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest

    链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...

  10. Ubuntu安装指定版本的docker

    系统环境: Ubuntu 16.0.4 安装版本: docker  17.03.2 在进现在这家公司初期,需要使用rancher部署一个k8s集群,由于rancher也是由docker启动的,加上k8 ...