CONOR - Alia and Cryptography

no tags 

Alia is world’s most widely acclaimed cryptographer. Recently she developed a new way to encrypt passwords over the internet. Instead of using the secret “Key”, now she intends to use a secret “Key Matrix” for encryption.

The “Key Matrix” consists of an integer matrix of dimensions m * n. Besides, there are four coordinates x1, y1, x2, y2. The “Key” can be retrieved from “Key Matrix” performing bitwise XOR(^) operation over all the integers present in rectangle having its upper left corner as (x1, y1) and lower right index as (x2, y2). (Note: the matrix is 0 based) Also Alia has developed new tools to regularly update his key to protect it from “attackers”. So she will update the values of some cells from time to time. You friend, being an expert hacker has finally retrieve the “Key Matrix” . Now he only needs to use the matrix to retrieve the key. Since this appears to be a tedious task, he turns to you. Help your friend by retrieving the secret “key” from the “key matrix”.

In brief, you’ll have to do the following two operations over the matrix

0 x1 y1 x2 y2 : Perform the XOR of all the integers present in the rectangle having its upper left corner as (x1, y1) and lower right index as (x2, y2).

1 x1 y1 k: Update the value at position (x1, y1) by k.

Input:

The first line of input will contain integers m and n (separated with space) specifying the dimensions of the matrix. This is followed by a m * n matrix (m rows and n columns) denoting the “Key Matrix”. The next line contains an integer q denoting the number of queries. Each of the following q lines contains a single query in the specified format.

Output:

For each query, print the value of the secret “Key” that you retrieve from the “Key Matrix”

Constraints

1 <= m, n < 600

1 <= q <= 20,000

0 <= x1, x2 <= m – 1

0 <= y1, y2 <= n – 1

0 <= Aij, k <= 10^8

Sample Input:

2 2

1 2

3 4

2

1 0 0 2

0 0 0 1 1

Sample Ouptut:

7

Explanation

The first query updates the value of (0, 0) to 2. Now the Key matrix appears like 2 2 3 4 Now for query 2 the secret key is the XOR of the value in the entire matrix So the key is 2 ^ 2 ^ 3 ^ 4 = 7


hide comments
azam_9: 2016-06-09 08:09:34

nice 1..

:.Mohib.:: 2015-07-19 06:23:38

Nice...on the top(Best solution) ;) :D

Last edit: 2015-07-19 06:41:28
Shubham Khandelwal: 2015-06-09 20:06:47

My 50th :)

Diksha Jaiswal: 2015-05-31 08:54:14

easy one...AC in one go :D

Last edit: 2015-05-31 08:56:26
Vaporeon: 2015-03-31 22:58:59

cin,cout--> TLE
sacnf printf--> AC
LOL :P

Abhilash: 2015-01-10 05:03:31

my first with >1 points

KRISHNA_SKY: 2014-12-25 16:35:00

Beware of data types..

Last edit: 2014-12-25 16:44:40

Added by:pranjuldb
Date:2014-09-09
Time limit:0.300s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Codehurdle