CF 548B Mike and Fun

Descripe

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.

Sample test(s)

Input

5 4 50 1 1 01 0 0 10 1 1 01 0 0 10 0 0 01 11 41 14 24 3

Output

34334

认真读好题。。CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#define REP(i, s, n) for(int i = s; i <= n; i ++)
#define REP_(i, s, n) for(int i = n; i >= s; i --)
#define MAX_N 500 + 10

using namespace std;

bool map[MAX_N][MAX_N];
int n, m, q;
int score[MAX_N];

int main(){
    scanf("%d%d%d", &n, &m, &q);
    memset(score, 0, sizeof(score));
    REP(i, 1, n){
        REP(j, 1, m) scanf("%d", &map[i][j]);
        int cnt = 0, tmp = 0;
        REP(j, 1, m){
            if(map[i][j] == 1) cnt ++;
            else{
                tmp = max(tmp, cnt);
                cnt = 0;
            }
        }
        tmp = max(tmp, cnt);
        score[i] = tmp;
    }

    int x, y, ans = 0;
    while(q --){
        scanf("%d%d", &x, &y);
        if(map[x][y] == 1) map[x][y] = 0;
        else map[x][y] = 1;

        int cnt = 0, tmp = 0; ans = 0;
        REP(i, 1, m){
            if(map[x][i] == 1) cnt ++;
            else {
                tmp = max(tmp, cnt);
                cnt = 0;
            }
        }
        tmp = max(tmp, cnt);
        score[x] = tmp;

        REP(i, 1, n) ans = max(ans, score[i]);
        printf("%d\n", ans);
    }

    return 0;
}
 
时间: 2024-08-13 05:35:32

CF 548B Mike and Fun的相关文章

CF 548A Mike and Fax

Descripe While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own bac

CodeForces 548B Mike and Fun (模拟)

题意:给定一个n*m的矩阵,都是01矩阵,然后每次一个询问,改变一个格的值,然后问你最大有数是多少. 析:就是按他说的模拟,要预处理,只要把每行的最大值记下来,当改变时,再更新这一行的最大值. 代码如下: #include<bits/stdc++.h> using namespace std; const int maxn = 500 + 5; int a[maxn][maxn]; int num[maxn]; int main(){ int n, m, q, x, y; while(cin

cf 547B. Mike and Feet dp

题意: n个矩阵排成一排,n<=2e5,高度分别为hei[i],宽度为1 对于一些连续的矩阵,矩阵的size为矩阵的个数,矩阵的strength为这些矩阵中高度最低的那一个高度 求:for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x. 对于每一个矩阵,我们先求出这个矩阵的l,r l表示这个矩阵左边最靠近它的小于它的矩阵的下标 r表示这个矩阵右边最靠近它的小于它的矩阵的下标 即在区间(l,r)

CF 345A Mike and Frog

题目 自己歪歪的做法WA了好多发. 原题中每一秒都相当于 x1 = f1(x1) x2 = f2(x2) 然后这是一个定义域和值域都在[0,m-1]的函数,显而易见其会形成一个环. 而且环长不超过m,所以实际上问题就分为了两部分: 1.x1变到a1,x2变到a2(h -> a的长度) 2.x1做循环,x2做循环直到同时为a1,a2.(a -> a的长度) 我们设第一步分别用了m1 s, m2 s,第二步用了 t1 s ,t2 s. 对于第一部分我们可以直接枚举吗,因为长度不超过m. 对于第二部

CF Round410 D. Mike and distribution

D. Mike and distribution 构造法 798D - Mike and distribution In the beginning, it's quite easy to notice that the condition " 2·(ap1?+?...?+?apk) is greater than the sum of all elements in A " is equivalent to " ap1?+?...?+?apk is greater than

CF Round410 C. Mike and gcd problem

C. Mike and gcd problem 一奇一偶需要两次操作,两个奇数需要一次操作. 798D - Mike and distribution In the beginning, it's quite easy to notice that the condition " 2·(ap1?+?...?+?apk) is greater than the sum of all elements in A " is equivalent to " ap1?+?...?+?a

CF 547 D. Mike and Fish

D. Mike and Fish http://codeforces.com/contest/547/problem/D 题意: 给定平面上n个点,将这些点染成红或者蓝色,要求每行.每列红色点与蓝色点数量的差的绝对值<=1.输出方案(保证有解). 分析: 参考popoqqq的博客 将每行每列分别看做一个点,给定的每个点(x,y)拆成x->y的边,那么连边后的图是一个二分图. 这样我们可以将边染色,使得与每个点相连的两种颜色差<=1. 于是对于所有的欧拉回路,我们可以直接交替染色. 但是会

【CF 547E】 Mike and Friends

题目 显然SAM版题,写它的原因就是我太颓了:之后学习了一下正规的广义SAM写法,争取以后不再写lst=1 代码 #include<bits/stdc++.h> #define re register const int maxn=4e5+5; const int M=maxn*30; struct E{int v,nxt;}e[maxn];char S[maxn>>1]; int l[M],r[M],d[M],tot,q; int lst,cnt,n,L,num,dep[maxn

关于cf[转]

还不怎么熟悉cf呢.. 你应当知道的关于Codeforces的事情 Codeforces简称: cf(所以谈论cf的时候经常被误会成TX的那款游戏).网址: codeforces.com 这是一个俄国的算法竞赛网站,由来自萨拉托夫州立大学.由Mike Mirzayanov领导的一个团队创立和维护,是一个举办比赛.做题和交流的平台.举办比赛和做题就不说了,“交流”指的是自带blog功能,可以求助/发布题解之类.官方语言是俄语和英语,因此可能有些偏僻的题目的题解是用俄语写的,别慌,扔给Google