题目: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. The method of using code coverage tool

    Please look at the following blog: http://blog.csdn.net/superqa/article/details/9060521 Use  ReportG ...

  2. IOS 特定于设备的开发:获取和使用设备姿势(通过手机方向控制3d物体显示)

    利用设备的机载陀螺仪可以实现,当你旋转手机屏幕时,里面的画面不会随着视图更新而移动,以平衡物理运动. 下面例子利用少量简单的几何变换执行该操作.他建立一个运动管理器,订阅设备运动更新,然后基于运动管理 ...

  3. IOS 特定于设备的开发:处理基本方向

    UIDevice类使用内置的orientation属性获取设备的物理方向.IOS设备支持这个属性的7个可能的值. >UIDeviceOrientationUnknown:方向目前未知. > ...

  4. grunt api 文档

    Grunt docs Grunt和 Grunt 插件是通过 npm 安装并管理的,npm是 Node.js 的包管理器. 安装 grunt-cli npm install grunt-cli -g 注 ...

  5. 动态更换view类的背景----StateListDrawable的应用

    StateListDrawable可以根据View的不同状态,更换不同的背景 可以应用如EditText,Button等中,以Button为例 系统中默认的按钮被按下的颜色和未点击时的颜色不一样,该种 ...

  6. Hibernate 配置详解(12) 补充

    hibernate.hbm2ddl.import_files_sql_extractor 这个配置项用于补充这篇文章: http://blog.csdn.net/stefwu/article/deta ...

  7. MyMVC框架的使用

    1)在web.config 中system.web 节点下加入例如以下代码 <pages controlRenderingCompatibilityVersion="4.0" ...

  8. golang printf

    1:  打印包括字段在内的实例的完整信息 同 %+V fmt.Printf("Hello world! %v","hufeng") 输出:Hello world ...

  9. 一步一步学c#(五):泛型

    泛型 性能 泛型的一个重要的优点是性能.system.collections和system.collections.generic名称空间的泛型和非泛型集和类.对值类型使用非泛型集合类,在把值类型转换 ...

  10. VS2015 启用“仅我的代码”

    在调试网站的时候,如果不勾选 [启用"仅我的代码"],会跳出一大堆异常,但是异常不作处理,非常烦人: 解决办法就是在 [调试]->[选项]->[勾选 启用"仅 ...