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了. 总结:下次一定要注意了,提交前一定要看 ...
随机推荐
- C++11: Multi-core Programming – PPL Parallel Aggregation Explained
https://katyscode.wordpress.com/2013/08/17/c11-multi-core-programming-ppl-parallel-aggregation-expla ...
- 20个Flutter实例视频教程-第12节: 流式布局 模拟添加照片效果
视频地址: https://www.bilibili.com/video/av39709290/?p=12 博客地址: https://jspang.com/post/flutterDemo.html ...
- Cookie和Session(3)
关于Cookie和Session Cookie和Session都为了用来保存状态信息,都是保存客户端状态的机制,它们都是为了解决HTTP无状态的问题而所做的努力. 1)cookie 是一种发送到客户浏 ...
- Linux系统调用及其效率
操作系统相关概念: 操作系统---管理计算机硬件与软件资源的软件,是用户与系统操作交互的接口,为在它上面运行的程序提供服务. 操作系统内核 ----操作系统的核心.负责管理系统的进程.内核.设备驱动程 ...
- Swift 4.0 中的 open,public,internal,fileprivate,private
1.private private访问级别所修饰的属性或者方法只能在当前类里访问. 2.fileprivate fileprivate访问级别所修饰的属性或者方法在当前的Swift源文件里可以访问. ...
- PL/SQL 的 事务处理
原文连接 http://blog.csdn.net/lhl6688/article/details/42874109 BEGIN DECLARE V_COUNT INTEGER; -- 表中记录 ...
- CentOS Linux 7 提示 lsof: 未找到命令
我们常使用 lsof -i:端口号 命令来查看某端口是否开放,如使用下面的命令,查看8080端口: lsof -i: 结果: 提示:lsof:未找到命令 解决办法 使用yum来安装lsof,命令如下: ...
- 2013 Noip提高组 Day2
3288积木大赛 正文 题目描述 春春幼儿园举办了一年一度的“积木大赛”.今年比赛的内容是搭建一座宽度为n的大厦,大厦可以看成由n块宽度为1的积木组成,第i块积木的最终高度需要是hi. 在搭建开始之前 ...
- android 通知(android 8.0可用)
final String CHANNEL_ID = "com.chao.channel.id"; final String CHANNEL_NAME = "com.c ...
- PostgreSQL-12-数据导入与导出
1.数据导入 - COPY FROM CREATE DATABASE c04_datacleaning; \c c04_datacleaning 创建新的数据库 COPY table_name [ ( ...