spoj#CONOR. Alia and Cryptography

Alia and Cryptography

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