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了. 总结:下次一定要注意了,提交前一定要看 ...
随机推荐
- intellj idea 使用
1. 导入包快捷 Alt + Enter 2. 查看方法注释,点击进入源码即可,若想和eclipse一样鼠标停留即可出现注释提示,开启方法为: Preferences->Editor->G ...
- mysql 事务 存储过程 函数
一:事务: 开启一个事务可以包含一些SQL语句,这些sql语句要么同时成功, 要么一个都别想成功, 称之我事务的原子性 事务用于将某些操作的多个SQL 作为原子性操作, 一旦有某一个出现错误, 即可以 ...
- HDU - 2612 Find a way 双起点bfs(路径可重叠:两个队列分别跑)
Find a way Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 51nod 1013【快速幂+逆元】
等比式子: Sn=(a1-an*q)/(1-q) n很大,搞一发快速幂,除法不适用于取膜,逆元一下(利用费马小定理) 假如p是质数,且gcd(a,p)=1,那么 a^(p-1)≡1(mod p).刚好 ...
- AndroidStudio给Unity打jar包
环境: AndroidStudio2.0 Unity4.68 AS打jar包 新建空工程 删除无用的MainActivity等. 新建Module Module选择Android Library,起名 ...
- bzoj 2007: [Noi2010]海拔【最小割+dijskstra】
上来就跑3e5的最大流--脑子抽了 很容易看出,每个地方的海拔都是0或1因为再高了没有意义,又,上去下来再上去没有意义,所以最后一定是从s连着一片0,剩下连着t一片1,然后有贡献的就是01交接的那些边 ...
- AFN的使用
http网络库是集XML解析,Json解析,网络图片下载,plist解析,数据流请求操作,上传,下载,缓存等网络众多功能于一身的强大的类库.最新版本支持session,xctool单元测试.网络获取数 ...
- builder模式的新学习
builder模式的新学习 静态工厂和构造器有个共同的局限性:他们不能很好的扩展到大量的可选参数.大多数产品在牧歌可选与中都会有非零的值 对于这种类,应该使用哪种构造器或者静态方法来进行编写?程序员一 ...
- C - Aladdin and the Flying Carpet
#include<bitset> #include<map> #include<vector> #include<cstdio> #include< ...
- git合并某次提交到某个分支
有的时候,在develop分支开发,是大家公用的开发分支,但是只想合并自己提交的到master,如何操作呢?那就要用cherry-pick了. 语法 git cherry-pick commitid ...