1477. Cryptography

Given three arrays ff, gg, hh of length 2m2^m, Bobo defines a cryptographic function enc(x,y)=(a,b)\mathrm{enc}(x, y) = (a, b) where

  • a=yg[xf[y]]a = y \oplus g[x \oplus f[y]],
  • b=xf[y]h[yg[xf[y]]]b = x \oplus f[y] \oplus h[y \oplus g[x \oplus f[y]]].

He also has qq questions (a1,b1),,(aq,bq)(a_1, b_1), \dots, (a_q, b_q).

For each (ai,bi)(a_i, b_i), find a pair of integers (x,y)(x, y) where 0x,y<2m0 \leq x, y < 2^m and enc(x,y)=(ai,bi)\mathrm{enc}(x, y) = (a_i, b_i). It is guaranteed that for each (ai,bi)(a_i, b_i), there exists a unique pair (x,y)(x, y) satisfying the condition.

Note: \oplus denotes the bitwise exclusive-or, i.e., xor.

输入

Note from SCNUOJ admin: we don't have the official test data sets, and all tests used here are randomly generated, so expect weak tests and/or even wrong input format. Contact one of the admins if you wish to improve the tests.

The input consists of several test cases terminated by end-of-file. For each test case,

The first line contains two integers mm and qq.

The second line contains 2m2^m integers f[0],,f[2m1]f[0], \dots, f[2^m - 1].

The third line contains 2m2^m integers g[0],,g[2m1]g[0], \dots, g[2^m - 1].

The forth line contains 2m2^m integers h[0],,h[2m1]h[0], \dots, h[2^m - 1].

For the following qq lines, the ii-th line contains two integers aia_i and bib_i.

  • 1m161 \le m \leq 16
  • 1q1051 \leq q \leq 10^5
  • 0f[i],g[i],h[i]<2m0 \leq f[i], g[i], h[i] < 2^m for each 0i<2m0 \leq i < 2^m
  • 0ai,bi<2m0 \leq a_i, b_i < 2^m for each 1iq1 \leq i \leq q
  • In each input, the sum of 2m2^m does not exceed 10510^5. The sum of qq does not exceed 10510^5.

输出

For each question, output two integers which denote the found xx and yy.

样例

标准输入 复制文本
2 2
0 1 2 3
1 2 3 0
2 3 0 1
0 1
2 3
1 1
0 0
0 0
0 0
0 0
标准输出 复制文本
3 0
1 2
0 0
标准输入 复制文本
1 1
0 0
0 0
0 0
0 0
标准输出 复制文本
0 0

来源

第六届中国大学生程序设计竞赛总决赛

登录以提交代码。
单点时限 1 秒
内存限制 128 MB
提交 8
通过 5