Mike and Fun

CodeForces - 548B

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 nm 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

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 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的更多相关文章

随机推荐

  1. PAT A1104 Sum of Number Segments (20 分)——数学规律,long long

    Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...

  2. maven 插

    一.maven插件元素 <?xml version="1.0" encoding="utf-8"?> <plugin> <!--插 ...

  3. ORA-10858:在要求输入数字处找到非数字字符

    今天在写sql语句的时候,运行报错:ORA-10858:在要求输入数字处找到非数字字符 在网上查了一下为什么会有这种错误,有一个建议是可能是写的sql语句中的日期没有处理.仔细看了一下自己写的代码 就 ...

  4. CF797F Mice and Holes 贪心、栈维护DP

    传送门 首先\(\sum c\)有些大,考虑将其缩小降低难度 考虑一个贪心:第一次所有老鼠都进入其左边第一个容量未满的洞(如果左边没有就进入右边第一个未满的洞),第二次所有老鼠都进入其右边第一个容量未 ...

  5. Luogu2045 方格取数加强版(K取方格数) 费用流

    题目传送门 题意:给出一个$N \times N$的方格,每个格子中有一个数字.你可以取$K$次数,每次取数从左上角的方格开始,每一次只能向右或向下走一格,走到右下角结束,沿路的方格中的数字将会被取出 ...

  6. angularjs的$window功能小练习

    我们想在一个文本框输入一些文字,然后点击铵钮,alert()出来. <div ng-app="alertApp" ng-controller="alertContr ...

  7. 在线图标制作,格式转换 ICON

    在线图标制作,格式转换 https://www.easyicon.net/covert/

  8. BootStrap学习(3)_导航菜单

    一.导航元素 1.表格导航或标签 以一个带有 class .nav 的无序列表开始. 添加 class .nav-tabs. <!DOCTYPE html> <html xmlns= ...

  9. Luogu P3398 仓鼠找sugar

    这还是一道比较好的树剖题(去你的树剖,LCA即可) 这里主要讲两种思路,其实都是很基本也很经典的 1 树链剖分 还是先讲一下这种算法吧,虽然写起来很烦(不过感觉写多了就习惯了,而且还有一种莫名的快感) ...

  10. QQ聊天记录备份助手 v1.0——搜索、备份、恢复QQ聊天记录文件,重装系统必备

    项目地址 https://github.com/guoyaohua/QQBackUp 开发环境 Netbean JAVA 功能描述 自动搜索硬盘中的QQ聊天记录文件 可选择的备份QQ数据记录 还原QQ ...