codeforces548B
Mike and Fun
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.
They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
Input
The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).
The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.
Output
After each round, print the current score of the bears.
Examples
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
3
4
3
3
4 sol:直接暴力模拟就可以了,每次修改一个点,只会影响一行的答案,所以只要修改一行就可以了,O(Q*m)水过。。。
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,Q,a[N][N];
int ans[N];
int main()
{
int i,j;
R(n); R(m); R(Q);
for(i=;i<=n;i++)
{
for(j=;j<=m;j++) R(a[i][j]);
}
for(i=;i<=n;i++)
{
int tmp=;
for(j=;j<=m;j++)
{
if(a[i][j]) tmp++;
else tmp=;
ans[i]=max(ans[i],tmp);
}
}
while(Q--)
{
int x,y,Max=;
R(x); R(y);
a[x][y]^=;
int tmp=; ans[x]=;
for(i=;i<=m;i++)
{
if(a[x][i]) tmp++;
else tmp=;
ans[x]=max(ans[x],tmp);
}
for(i=;i<=n;i++) Max=max(Max,ans[i]);
Wl(Max);
}
return ;
}
/*
input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
output
3
4
3
3
4
*/
codeforces548B的更多相关文章
随机推荐
- JAVA 第七周学习总结
20175308 2018-2019-2 <Java程序设计>第七周学习总结 教材学习内容总结 本周学习第八章:常用实用类 String类: String类位于java.lang包中,被定 ...
- Objective-C 类簇深入理解
类簇(class cluster),是一种基于抽象工厂的设计模式,广泛运用于系统的Foundation框架.顾名思义,即一坨类,这里指的是继承自同一父类的一组私有子类.这种实现既可以简化公共接口,又保 ...
- linux 服务器安全加固和内核参数调优 nf_conntrack
0.内部设置跳板机,服务器只能通过跳板机登录1.禁止ROOT用户远程登录和登录端口 禁止ROOT用户远程登录 .打开 /etc/ssh/sshd_config PermitRootLogin no . ...
- Tensorflow[源码安装时bazel行为解析]
0. 引言 通过源码方式安装,并进行一定程度的解读,有助于理解tensorflow源码,本文主要基于tensorflow v1.8源码,并借鉴于如何阅读TensorFlow源码. 首先,自然是需要去b ...
- sql函数创建
语法: CREATE [OR REPLACE] FUNCTION function_name (arguments) RETURNS return_datatype AS $variable_name ...
- NIO之缓冲区
NIO引入了三个概念: Buffer 缓冲区 Channel 通道 selector 选择器 1.java.io优化建议 操作系统与Java基于流的I/O模型有些不匹配.操作系统要移动的是大块数据(缓 ...
- centos下部署redis服务环境及其配置说明
Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的开发工作由VMware主 ...
- 多校寒训TaoTao要吃鸡dp
题目描述 Taotao的电脑带不动绝地求生,所以taotao只能去玩pc版的荒野行动了, 和绝地求生一样,游戏人物本身可以携带一定重量m的物品,装备背包 之后可以多携带h(h为0代表没有装备背包)重量 ...
- JS 实现计算一段文字中的字节数,字母数,数字数,行数,汉字数。
看到了匹配,第一个想到了用正则表达式,哈哈,果然很方便.不过正则表达式高深莫测!我还没有研究明白啊..目前学了点皮毛.代码如下: <!DOCTYPE html PUBLIC "-//W ...
- Peer Programming Project: 4 Elevators Scheduler 附加题 157 165
1.改进电梯调度的interface 设计, 让它更好地反映现实, 更能让学生练习算法, 更好地实现信息隐藏和信息共享. 每个电梯增加目标楼层数组,这样可以更好地进行任务的分配,在我们的电梯中,这个数 ...