cf div2 238 c
1 second
256 megabytes
standard input
standard output
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:
- given a row index i, flip all the values in the i-th row in A;
- given a column index i, flip all the values in the i-th column in A;
- 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?
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:
- 1 i — flip the values of the i-th row;
- 2 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++.
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.
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
01001 这个题目有个
#include <cstdio> using namespace std; int n,p; int main() {
scanf("%d",&n);
int ans = ;
for(int i = ; i <= n; ++i) {
for(int j = ; j <= n; ++j) {
int v;
scanf("%d",&v);
if(i == j)
ans ^= v;
}
} scanf("%d",&p);
for(int i = ; i <= p; ++i) {
int ch,v;
scanf("%d",&ch);
if(ch == ) {
printf("%d",ans);
}
else {
scanf("%d",&v);
ans ^= ;
}
} return ; }
规律,除了主对角线的元素自己与自己相乘,其他的元素相乘的组合每个都会出现两次,即他们的和必定是0所以只需要考虑主对角线的元素自行相乘的就可以了
cf div2 238 c的更多相关文章
- cf div2 238 D
D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- cf div2 234 D
D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 离线dfs CF div2 707 D
http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...
- cf div2 239 D
D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- cf div2 236 D
D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 237 D
D. Minesweeper 1D time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- cf div2 235 D
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- cf div2 234 E
E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...
- CF div2 D BFS
http://codeforces.com/contest/676/problem/D 题目大意: 勇者去迷宫杀恶龙.迷宫是有n*m的方格子组成的.迷宫上有各种记号,这些记号表达着能走的方向.当且仅当 ...
随机推荐
- OracleINSERT提示IGNORE_ROW_ON_DUPKEY_INDEX
OracleINSERT提示IGNORE_ROW_ON_DUPKEY_INDEX insert提示IGNORE_ROW_ON_DUPKEY_INDEX 在 insert into table a() ...
- 在.net程序中使用System.Net.Mail来发送邮件
System.Net.Mail是微软自家提供的工具,在.net程序中可以使用该空间中的SmtpClient实例来实现邮件的发送. 使用System.Net.Mail空间与Web.config配置相配合 ...
- Objective-C中Block语法、Block使用以及通过Block实现数组排序
Block:语法块,本质上是匿名函数(没有名称的函数) 标准C里面没有Block,C语言的后期扩展版本,加入了匿名函数 在C++.JS.Swift等语言有类似语法,叫做闭包 Block语法和C语言里的 ...
- 数据持久化-Plist文件写入
数据持久化,常见4种:归档,plist文件,sqlite,coreData.今天复习的是plist文件读写. // // ViewController.m // Test_Plist // // Cr ...
- MVC4.0 利用IActionFilter实现简单的后台操作日志功能
首先我们要了解MVC提供了4种常用的拦截器:IActionFilter(Action拦截器接口).IExceptionFilter(异常拦截器接口).IResultFilter(Result拦截器接口 ...
- 自己编写基于MVC的轻量级PHP框架
做WEB开发已有三年,每次都写重复的东西, 因此,想自己写一下框架,以后开发方便.本人之前asp.NET一年开发,jsp半年,可是后来因为工作的原故换成PHP.其实很不喜欢PHP的语法.还有PHP的函 ...
- django概述
一.django的特点 1.提供一体化的web解决方案,什么叫一体化:mvc 2.等你玩儿牛逼了可以拔插组件,换成自己顺手或者更牛逼的组件
- C++中栈的出栈,入栈规则:A,B,C,D,E
考题: 栈底至栈顶一次存放元素 ABCD 在第五个元素E入栈之前 栈中元素可以出栈,则出栈序列可能是_____a d___________. a. ABCED b. DBCEA c. CD ...
- java字符串替换函数高效实现
public static String removeStr(String src, String str) { if (src == null || str == null) return src; ...
- C++中的set和java的hashset有何区别?
以前对C++的STL容器烂熟于心,两年没碰过C++了,现在已经很生疏了.工作原因转战java,对java的容器不甚了解,特别是每看到一种容器,不由自主地拿起和C++对比.C++中的set和java的h ...