F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Reverse Game

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 162    Accepted Submission(s): 82


Problem Description
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)$.
 

Input
The first line of the input contains an integer $T (1 \le T \le 15)$, denoting the number of test cases.
In each test case, the first line contains one integer N, which means the size of the matrix.
In the next $N$ lines, each line contains $N$ integers(0 or 1) means the color of each color. 1 represents black and 0 represents white.
Then the integer $Q$ represents the number of reversals that the host does. Each line of the $Q$ lines contains several numbers. If the first number is 1, the next one number $y$ is the columns of the reversal. If the first number is 2, the next two numbers $x$ and $y$ represents the position of the reversal.
$2 \leq N \leq 200$
$1 \leq Q \leq 20000$
 

Output
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
 

Sample Input
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
 

Sample Output
4 5 4 3 2 2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 12:36:06, Gzip enabled