Codeforces Round #316 (Div. 2C) 570C Replacement
题目: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的更多相关文章
- 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. 2) C Replacement 扫描法
先扫描一遍得到每个位置向后连续的'.'的长度,包含自身,然后在扫一遍求出初始的合并次数. 对于询问,只要对应位置判断一下是不是'.',以及周围的情况. #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了. 总结:下次一定要注意了,提交前一定要看 ...
随机推荐
- (Problem 92)Square digit chains
A number chain is created by continuously adding the square of the digits in a number to form a new ...
- css兼容问题与实践归纳总结
css兼容问题与实践归纳总结 一.IE6/7 原生块元素与display:inline-block; <div style="display:inline-block;"&g ...
- Html 小插件6 百度新闻插件
新闻免费代码"http://news.baidu.com/newscode.html ,便可在输入希望订阅的关键词后,根据相关选项的设置,百度便非常快的在当前页面的文本编辑框内生成相关代码. ...
- elk 分布式部署
这个logstash 读取日志 是增量的 还是怎么读的? 定时每秒读增量 机器配置: elasticsearch-192.168.32.80 elasticsearch-192.168.32.81 e ...
- Quick Tip: Outline Elements on Hover
How to get the xpath by clicking an html element How to get the xpath by clicking an html element Qu ...
- 取得phpcms网站下所有栏目的内容链接
今天做了一个小功能,就是取得公司网站的所有文章的内容地址,公司网站是用phpcms 做的,感觉还蛮简单的,记录下: <?php $conf['DB_USER'] = 'user'; $conf[ ...
- 使用资源监控工具 glances
http://www.ibm.com/developerworks/cn/linux/1304_caoyq_glances/ glances 可以为 Unix 和 Linux 性能专家提供监视和分析性 ...
- 黑客瑞士军刀NC使用教程
###################################################################### 1. 写在前面的话 ################### ...
- uploadify 使用 详细 说明
简单 常用的 时间 有点 紧 先写 这点 , 有时间 在更新 下面有 例子 链接 不过要 自己 摘 一下 很简单的啦 <script type="text/javascrip ...
- java web分享ppt大纲 -- servlet容器简介
今天在公司分享了java web的ppt,把ppt大纲放在这里,希望可以帮助需要的人 servlet容器简介 定义 狭义上的,servlet容器为java Web应用提供运行时环境,负责管理servl ...