博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces - 405C
阅读量:4987 次
发布时间:2019-06-12

本文共 2756 字,大约阅读时间需要 9 分钟。

 

Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

 

Description

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 line aij (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 Input

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

Source

#include 
int i,j,n,t1,t2,t3,k,q,a[1005][1005],sum=0,ans;int jisuan(int n,int a[1005][1005]){ sum=0; for (i=0;i

 

转载于:https://www.cnblogs.com/Ritchie/p/5425143.html

你可能感兴趣的文章
图解HTTPS协议
查看>>
iOS -NSArray
查看>>
dom中表格操作
查看>>
Centos7安装Typecho详细教程
查看>>
Object Death in Garbage Collector's Perspective
查看>>
Redis基础知识之————使用技巧(持续更新中.....)
查看>>
feathers button 支持中文(非bitmap字体)
查看>>
帖子收藏
查看>>
scrapy安装教程
查看>>
装饰器
查看>>
19、AJAX
查看>>
NTP时间服务器的配置
查看>>
js011-DOM扩展
查看>>
JPA api 学习
查看>>
C#JWT验证
查看>>
Java transient关键字使用小记
查看>>
图片轮播
查看>>
PAT 乙级 1077
查看>>
iphone开发我的新浪微博客户端-用户登录账号添加篇(1.5)
查看>>
LeetCode ZigZag Conversion
查看>>