题目:Click here

题意:看一下题目下面的Note就会明白的。

分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用。

直接判断:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int M = 3e5+; int n, m;
char str[M];
int main() {
while( ~scanf("%d %d", &n, &m ) ) {
scanf("%s", str );
int len = strlen( str );
int ans = ;
for( int i=; i<len; i++ )
if( str[i]==str[i-] && str[i]=='.' )
ans++;
for( int i=; i<m; i++ ) {
int pos; char s;
scanf("%d %c", &pos, &s );
pos--;
if( str[pos]=='.' && s!='.' ) {
if( pos> && str[pos-]=='.' ) ans--;
if( pos<n- && str[pos+]=='.' ) ans--;
}
else if( str[pos]!='.' && s=='.' ) {
if( pos> && str[pos-]=='.' ) ans++;
if( pos<n- && str[pos+]=='.' ) ans++;
}
str[pos] = s;
printf("%d\n", ans );
}
}
return ;
}

树状数组优化(上面的方法更快):

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int M = 3e5+; int n, m;
char str[M];
int C[M];
int query( int x ) {
int ret = ;
while( x > ) {
ret += C[x];
x -= x&-x;
}
return ret;
}
void update( int x, int y ) {
while( x <= n ) {
C[x] += y;
x += x&-x;
}
}
int main() {
while( ~scanf("%d %d", &n, &m ) ) {
scanf("%s", str );
int len = strlen( str );
memset( C, , sizeof(C) );
for( int i=; i<len; i++ )
if( str[i]==str[i-] && str[i]=='.' )
update( i, );
for( int i=; i<m; i++ ) {
int pos; char s;
scanf("%d %c", &pos, &s );
pos--;
if( str[pos]=='.' && s!='.' ) {
if( pos> && str[pos-]=='.' ) update( pos, - );
if( pos<n- && str[pos+]=='.' ) update( pos+, - );
}
else if( str[pos]!='.' && s=='.' ) {
if( pos> && str[pos-]=='.' ) update( pos, );
if( pos<n- && str[pos+]=='.' ) update( pos+, );
}
str[pos] = s;
printf("%d\n", query( len- ) );
}
}
return ;
}

Codeforces Round #316 (Div. 2C) 570C 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. 2) C Replacement 扫描法

    先扫描一遍得到每个位置向后连续的'.'的长度,包含自身,然后在扫一遍求出初始的合并次数. 对于询问,只要对应位置判断一下是不是'.',以及周围的情况. #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. Tensorflow tflearn 编写RCNN

    两周多的努力总算写出了RCNN的代码,这段代码非常有意思,并且还顺带复习了几个Tensorflow应用方面的知识点,故特此总结下,带大家分享下经验.理论方面,RCNN的理论教程颇多,这里我不在做详尽说 ...

  2. 身份验证cookies和Token

    后端服务器有两种基本的身份验证:1.是基于Cookie的身份验证,使用服务器端的cookie来对每次请求的用户进行身份验证.2. 较新的方法,基于令牌Token的认证,依赖于被发送到服务器上每个请求的 ...

  3. 让 QtWebkit 支持跨域CROS - nowboy的CSDN博客 - 博客频道 - CSDN.NET

    让 QtWebkit 支持跨域CROS - nowboy的CSDN博客 - 博客频道 - CSDN.NET 让 QtWebkit 支持跨域CROS 2013-05-23 22:05 450人阅读 评论 ...

  4. Android:广播接收器(BroadCastReceiver)要点随笔。

    @@@描述         广播接收器可以收到 Context.sendBroadcast或者Context.sendOrderedBroadcast发出的意图(intent).   @@@Local ...

  5. cocos2d-x3.9利用cocos引擎一键打包Android平台APK(C++小白教程)

    链接地址:http://www.cocoachina.com/bbs/read.php?tid=333937 cocos2d-x3.9利用cocos引擎一键打包Android平台APK(C++小白教程 ...

  6. Problem B The Blocks Problem(vector的使用)

    题目链接:Problem B 题意:有n块木块,编号为0~n-1,要求模拟以下4种操作(下面的a和b都是木块编号) 1. move a onto b: 把a和b上方的木块全部归位,然后把a摞在b上面. ...

  7. BZOJ 1449: [JSOI2009]球队收益( 最小费用最大流)

    先考虑假如全部输了的收益. 再考虑每场比赛球队赢了所得收益的增加量,用这个来建图.. --------------------------------------------------------- ...

  8. 修改spfile导致oracle无法启动

    今天尝试着调整一下数据库的性能,由于疏忽没有做好备份(spfile.ora),直接修改了MEMORY_TARGET参数,alter system set MEMORY_TARGET=4096m;导致重 ...

  9. MyEclipse 8.5整合Git,并在Github上发布项目(转)

    下载Eclipse的git插件——EGit.下载网址http://download.eclipse.org/egit/updates-1.3/org.eclipse.egit-updatesite-1 ...

  10. WebAppScaner

    https://www.ohloh.net/p/simple-scan/ https://code.google.com/p/skipfish/ http://code.google.com/p/wa ...