Problem G. Reverse Game
时间限制 5000 ms
内存限制 64 MB
One day, Umaru was enjoying Coke and potato chips as usual. Suddenly, an intellectual problem appeared on the television and the person who asked the problem first and correctly will get the latest《Jump》. Umaru really wants to get the 《Jump》so she told her brother the problem and begged him to help her. But her brother didn’t know how to do it, so he told you the problem and asked you for help.
There was a $N×N$ matrix and each grid is black or white. The host reversed the color of the grid or reversed the color of the whole columns. Then the problem was how many white and black connected components. (If two grids have a common edge, we think they are connected.) To increase difficulty, the grid $(i,1)$ and the grid $(i,N)$ are connected. $(1\leq i \leq N)$.
输入数据
输出数据
The output contains $Q$ lines. The $i$-th line contains two integers which represent the number of the white and black connected components after the first $i$ operations
样例输入
复制
1
5
0 0 0 1 1
1 1 0 0 1
0 1 1 0 1
1 0 0 1 0
1 0 1 1 0
3
2 2 5
2 3 4
1 1
样例输出
$ Mathjax font initiator $