#P2117. 小Z的矩阵

小Z的矩阵

Description

Xiao Z has recently become obsessed with matrices. He defines a characteristic function GG for a special kind of matrix. For an N×NN \times N matrix AA where every element of AA is 00 or 11, define $\displaystyle G(A) = \left(\sum_{i = 1}^n\sum_{j = 1}^n A_{i, j}\cdot A_{j, i}\right) \bmod 2$. For example:

$$\begin{pmatrix} 1 & 1 & 1\\ 0 & 1 & 1\\ 1 & 0 & 0\\ \end{pmatrix}$$

For the 3×33 \times 3 matrix AA above, $G(A)=(1\times 1+1\times 0+1\times 1+0\times 1+1\times 1+1\times 0+1\times 1+ 0\times 1+0\times 0) \bmod 2 = 0$.

Of course, querying the GG value of a single matrix is too simple. Along with giving you an N×NN \times N matrix, Xiao Z also gives you QQ operations, described as follows:

  • Operation 1: of the form 1 x, which means “flip” all elements in row xx.
  • Operation 2: of the form 2 x, which means “flip” all elements in column xx.
  • Operation 3: an integer 3, which asks for the current value of the characteristic function GG.

“Flip” means changing 11 to 00 and 00 to 11.

Input Format

The first line contains two positive integers N,QN, Q. NN is the number of rows (and columns) of the matrix, and QQ is the number of operations.

The next NN lines describe an N×NN \times N matrix AA, with 0Ai,j10 \le A_{i, j} \le 1.

The next QQ lines contain the QQ operations.

Output Format

Output a single line consisting of several numbers with no spaces, representing the result of each operation (no output for operations 1 and 2).

3 12
1 1 1
0 1 1
1 0 0
3
2 3
3
2 2
2 2
1 3
3
3
1 2
2 1
1 1
3

01001

Hint

Constraints

  • For 30%30\% of the testdata, N100N \le 100, Q105Q \le 10^5.
  • For 100%100\% of the testdata, N1,000N \le 1{,}000, Q5×105Q \le 5 \times 10^5.

Translated by ChatGPT 5