codeforces-scrape

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

405C.md (3044B)


      1 Source: https://codeforces.com/problemset/problem/405/C
      2 
      3 C. Unusual Product
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.
     22 
     23 The dot product of two integer number vectors *x* and *y* of size *n* is the sum of the products of the corresponding components of the vectors. The unusual square of an *n* × *n* square matrix *A* is defined as the sum of *n* dot products. The *i*-th of them is the dot product of the *i*-th row vector and the *i*-th column vector in the matrix *A*.
     24 
     25 Fortunately for Chris, he has to work only in *GF*(2)! This means that all operations (addition, multiplication) are calculated modulo 2. In fact, the matrix *A* is binary: each element of *A* is either 0 or 1. For example, consider the following matrix *A*:
     26 
     27  ![](https://espresso.codeforces.com/2c3ad2b03d2ce423c3d5acf492c838080055234f.png) 
     28 
     29 The unusual square of *A* is equal to (1·1 + 1·0 + 1·1) + (0·1 + 1·1 + 1·0) + (1·1 + 0·1 + 0·0) = 0 + 1 + 1 = 0.
     30 
     31 However, there is much more to the homework. Chris has to process *q* queries; each query can be one of the following:
     32 
     33 1. given a row index *i*, flip all the values in the *i*-th row in *A*;
     34 2. given a column index *i*, flip all the values in the *i*-th column in *A*;
     35 3. find the unusual square of *A*.
     36 
     37 To flip a bit value *w* means to change it to 1 - *w*, i.e., 1 changes to 0 and 0 changes to 1.
     38 
     39 Given the initial matrix *A*, output the answers for each query of the third type! Can you solve Chris's homework?
     40 
     41 Input
     42 
     43 The first line of input contains an integer *n* (1 ≤ *n* ≤ 1000), the number of rows and the number of columns in the matrix *A*. The next *n* lines describe the matrix: the *i*-th line contains *n* space-separated bits and describes the *i*-th row of *A*. The *j*-th number of the *i*-th line *a**ij* (0 ≤ *a**ij* ≤ 1) is the element on the intersection of the *i*-th row and the *j*-th column of *A*.
     44 
     45 The next line of input contains an integer *q* (1 ≤ *q* ≤ 106), the number of queries. Each of the next *q* lines describes a single query, which can be one of the following:
     46 
     47 * 1 *i* — flip the values of the *i*-th row;
     48 * 2 *i* — flip the values of the *i*-th column;
     49 * 3 — output the unusual square of *A*.
     50 
     51 Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.
     52 
     53 Output
     54 
     55 Let the number of the 3rd type queries in the input be *m*. Output a single string *s* of length *m*, where the *i*-th symbol of *s* is the value of the unusual square of *A* for the *i*-th query of the 3rd type as it appears in the input.
     56 
     57 Examples
     58 
     59 Input
     60 
     61 ```
     62 3  
     63 1 1 1  
     64 0 1 1  
     65 1 0 0  
     66 12  
     67 3  
     68 2 3  
     69 3  
     70 2 2  
     71 2 2  
     72 1 3  
     73 3  
     74 3  
     75 1 2  
     76 2 1  
     77 1 1  
     78 3
     79 ```
     80 
     81 Output
     82 
     83 ```
     84 01001
     85 ```