Codeforces Round #316 (Div. 2) C Replacement 扫描法
先扫描一遍得到每个位置向后连续的'.'的长度,包含自身,然后在扫一遍求出初始的合并次数。
对于询问,只要对应位置判断一下是不是'.',以及周围的情况。
#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 扫描法的更多相关文章
- 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 ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树
C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...
- Codeforces Round #316 (Div. 2) C. Replacement
题意:给定一个字符串,里面有各种小写字母和' . ' ,无论是什么字母,都是一样的,假设遇到' . . ' ,就要合并成一个' .',有m个询问,每次都在字符串某个位置上将原来的字符改成题目给的字符, ...
- Codeforces Round #316 (Div. 2) C. Replacement(线段树)
C. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #316 (Div. 2C) 570C Replacement
题目:Click here 题意:看一下题目下面的Note就会明白的. 分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用. 直接判断: #include <bits/stdc++. ...
- Codeforces Round #316 (Div. 2)
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #316 (Div. 2) C 思路/模拟
C. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #316 (Div. 2) (ABC题)
A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...
- 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了. 总结:下次一定要注意了,提交前一定要看 ...
随机推荐
- python 之生产者消费者模型
进程实现: import time,random from multiprocessing import Process,Queue def producer(name,q): count= 0 wh ...
- 2-1赋值运算符 & 2-2自增自减运算符 &2-3
2-1赋值运算符 先定义一个变量,把定义好的变量在赋值给另外一个变量.变向之间的互相赋值 2-2自增自减运算符 元素符,放在变量前和变量后的区别 先进行自增运算,再进行赋值运算.这里先进行num1的+ ...
- Identity Server 4 原理和实战(完结)_单点登录实例(添加Flask客户端,Express.js的API)
idp授权资源的添加 如果下面哪个客户端想访问api2这个资源的话 就把它写上scope里面就可以了 nodeJS的客户端 python的库 MVC客户端分别访问API和API2 python客户端演 ...
- awk用法总结
简介 awk的命名来自于他的三位创始人Alfred Aho .Peter Weinberger 和 Brian Kernighan 的姓氏的首字母. 有多种版本:New awk(nawk),GNU a ...
- wmware7安装xp错误:虚拟CPU已经入关闭状态
wm7安装xp错误提示: 虚拟CPU已经入关闭状态.这会造成物理计算机重新启动.这可能是虚拟机操作系统的错误或VMware Workstation软件中的一个配置不正确. 这种情是硬盘模式为AHCI模 ...
- sqlserver——视图
数据库中的视图是一个虚拟表.同真实的表一样,视图包含一系列带有名称的列和行数据,行和列数据用来自由定义视图和查询所引用的表,并且在引用视图时动态产生.本篇将通过一些实例来介绍视图的概念,视图的作用,创 ...
- c#重写 重载
重写:当一个子类继承一父类,而子类中的方法与父类中的方法的名称,参数个数.类型都完全一致时,就称子类中的这个方法重写了父类中的方法. 重写:通常,派生类继承基类的方法.因此,在调用对象继承方法的时候, ...
- Swift异常处理
在Swift里,抛出的异常必须继承Error这个协议.那么这个协议是什么呢? 按住command再点击Error我们可以看到, public protocol Error { } extension ...
- 64位Win7中7zip无法关联文件的问题
问题1:win7x64中安装了7zip,在解压文件右键打开无法关联文件. 解决方法1:在开始菜单中打开7-zip File Manage->工具 ->选项 ->7-zip 勾选“添加 ...
- Ajax登陆,使用Spring Security缓存跳转到登陆前的链接
Spring Security缓存的应用之登陆后跳转到登录前源地址 什么意思? 用户访问网站,打开了一个链接:(origin url)起源链接 请求发送给服务器,服务器判断用户请求了受保护的资源. 由 ...