#P8279. 「MCOI-08」Fill In REMATCH

    ID: 6459 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>洛谷原创Special JudgeO2优化位运算,按位构造洛谷月赛

「MCOI-08」Fill In REMATCH

Description

Dream has an integer array a1,a2,,ana_1,a_2,\dots,a_n of length nn (1n1051\le n\le 10^5). For i=1,2,,ni=1,2,\dots,n, it holds that 0ai<2600\le a_i<2^{60}.

He computed the prefix XOR array pi=a1a2aip_i=a_1\oplus a_2\oplus\dots\oplus a_i and the suffix XOR array si=aiai+1ans_i=a_i\oplus a_{i+1}\oplus\dots\oplus a_n.

Now Tommy has replaced a total of nn elements in pp and ss with 1-1. Given the current arrays pp and ss, restore any possible array a1,a2,,ana_1,a_2,\dots,a_n.

It is guaranteed that a valid solution exists.

Input Format

This problem contains multiple test cases. The first line contains a positive integer tt, the number of test cases. Then follow tt test cases. For each test case:

The first line contains a positive integer nn (1n1051\le n\le 10^5).

The next line contains nn integers p1,p2,,pnp_1,p_2,\dots,p_n.

The next line contains nn integers s1,s2,,sns_1,s_2,\dots,s_n.

Output Format

For each test case:

Output nn non-negative integers a1,a2,,ana_1,a_2,\dots,a_n that satisfy the above conditions.

1
4
-1 34 367 -1
3178 -1 -1 3333
3 33 333 3333

Hint

For 100%100\% of the testdata, 1n,n1051\le n,\sum n\le 10^5, [pi=1]+[si=1]=n\sum [p_i=-1]+\sum [s_i=-1]=n, and a valid solution is guaranteed to exist.

  • Subtask 1 (10 pts): n4n\le 4, pi,si<2p_i,s_i<2.
  • Subtask 2 (10 pts): n100n\le 100.
  • Subtask 3 (20 pts): pi,si<2p_i,s_i<2.
  • Subtask 4 (60 pts): No special constraints.

Translated by ChatGPT 5