cf——A. Unusual Product

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.

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.

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:

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.

However, there is much more to the homework. Chris has to process q queries; each query can be one of the following:

  1. given a row index i, flip all the values in the i-th row in A;
  2. given a column index i, flip all the values in the i-th column in A;
  3. find the unusual square of A.

To flip a bit value w means to change it to 1 - w, i.e., 1 changes to 0 and 0 changes to 1.

Given the initial matrix A, output the answers for each query of the third type! Can you solve Chris's homework?

Input

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 nlines 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 lineaij (0 ≤ aij ≤ 1) is the element on the intersection of the i-th row and the j-th column of A.

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:

  • i — flip the values of the i-th row;
  • i — flip the values of the i-th column;
  • 3 — output the unusual square of A.

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++.

Output

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.

Sample test(s)
input
3
1 1 1
0 1 1
1 0 0
12
3
2 3
3
2 2
2 2
1 3
3
3
1 2
2 1
1 1
3
output

01001

#include<iostream>
#include<cstring>
#include <cstdio>
using namespace std;
int a[1005][1005];
//^相同为1 不同为0
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        int ans=0;
        for(int i=0; i<n; i++)
        {
            int temp=0;
            for(int j=0; j<n; j++)
            {
                if(a[i][j]==1&&a[j][i]==1)
                    temp^=1;
            }
            ans^=temp;
        }
        int t;
        scanf("%d",&t);
        for(int i=0; i<t; i++)
        {
            int f;
            scanf("%d",&f);
            if(f<=2)
            {
                int e;
                scanf("%d",&e);
                ans^=1;
            }
            else
                cout<<ans;
        }
        cout<<endl;
    }
    return 0;
}


.equals(Obje​​ct)方法在Java中用于比较两个对象是否相等。它检查两个对象的内容是否相同而不是引用是否相同。通常,我们可以使用"=="运算符来比较基本数据类型的值或判断两个对象引用是否相等。但是,对于比较复杂的对象,比如自定义的类对象,它们可能具有相同的属性值,但却不被认为是相等的,因为它们不是同一个对象的实例。 .equals(Obje​​ct)方法为我们提供了一种自定义比较两个对象内容的方式。这个方法是从Object类继承而来的,因此在所有的类中都可用。某些类,比如String类、Integer类等,已经重写了.equals(Obje​​ct)方法,以便实现比较它们的内容。但是,对于自定义的类,如果不重写.equals(Obje​​ct)方法的话,将继承Object类的默认实现,即比较两个对象的引用是否相等。 与"=="运算符相比,.equals(Obje​​ct)方法的作用更灵活、更具体。它可以根据具体的比较规则来决定两个对象是否相等。但是,由于.equals(Obje​​ct)方法的默认实现比较对象的引用,所以在自定义类中使用.equals(Obje​​ct)方法时,需要注意重写该方法以实现我们自己的比较逻辑。 综上所述,.equals(Obje​​ct)方法在Java中是相对不寻常的,因为大部分时候我们可以使用"=="运算符来比较对象引用是否相等。然而,在比较复杂对象内容时,.equals(Obje​​ct)方法提供了一种更具体、更灵活的比较方式。这是Java中为了满足不同需求而提供的一种对象比较工具。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值