codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

548B.md (1983B)


      1 Source: https://codeforces.com/problemset/problem/548/B
      2 
      3 B. Mike and Fun
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23  ![](https://espresso.codeforces.com/664a0b2842f4c339e6ead1d510910154a2948b98.png) 
     24 
     25 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.
     26 
     27 Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
     28 
     29 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.
     30 
     31 Input
     32 
     33 The first line of input contains three integers *n*, *m* and *q* (1 ≤ *n*, *m* ≤ 500 and 1 ≤ *q* ≤ 5000).
     34 
     35 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).
     36 
     37 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.
     38 
     39 Output
     40 
     41 After each round, print the current score of the bears.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 5 4 5  
     49 0 1 1 0  
     50 1 0 0 1  
     51 0 1 1 0  
     52 1 0 0 1  
     53 0 0 0 0  
     54 1 1  
     55 1 4  
     56 1 1  
     57 4 2  
     58 4 3
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 3  
     65 4  
     66 3  
     67 3  
     68 4
     69 ```