#P7819. [RC-05] Xor Matrix

[RC-05] Xor Matrix

Description

You are given an n×mn\times m matrix. The value in row ii and column jj is (i1)m+j(i-1)m+j.

For each query, compute the base-kk xor sum of the submatrix with top-left corner (x,y)(x,y) and bottom-right corner (z,w)(z,w) (that is, addition without carry. For example, in base 99, (45)9 xor (87)9=(33)9(45)_9\ \mathrm{xor}\ (87)_9=(33)_9).

Input Format

To reduce the number of test points, this problem contains multiple queries in a single test. The time limit has been adjusted according to the number of query groups.

The first line contains two positive integers n,mn,m.

The next line contains an integer qq, the number of queries.

The next qq lines each contain five positive integers x,y,z,w,kx,y,z,w,k, describing one query.

Output Format

Output qq lines. Each line contains one integer, the answer to the corresponding query.

15 233
2
1 1 3 3 2
4 8 14 200 24
319
7032
939 943 10
94 618 848 927 92
421 16 525 45 99
77 524 662 779 82
316 630 910 669 51
857 241 890 447 9
44 30 95 409 83
408 302 804 331 73
571 42 761 334 70
419 220 704 855 54
432 80 669 799 52
33786429
97803
41147634
6638925
738
96232
19796958
14611599
6717042
6402992

Hint

This problem uses bundled judging.

For all data, 1n,mnm10101\le n,m\le nm\le 10^{10}, 1q101\le q\le 10, 1xzn1\le x\le z\le n, 1ywm1\le y\le w\le m, 2k1092\le k\le 10^9.

The detailed Constraints are shown in the table below:

Subtask ID nmnm Special Property Score
11 1010\le 10^{10} n105n\le 10^5 1818
22 2×109\le 2\times 10^{9} None 6161
33 1010\le 10^{10} 2121

Subtask Dependencies

On Luogu, this problem does not have subtask dependencies. On InfOJ, subtask 33 depends on subtask 11. During final scoring, the version with subtask dependencies will be used.

Translated by ChatGPT 5