Déjà Vu!
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Problem 5: Déjà Vu!
Although he had already reached the Steins Gate, Rintaro Okabe, burdened by the heavy load of traversing various world lines, uncontrollably shifted into the CS100 world. "It seems this day has come after all," Rintaro Okabe tried to clear his mind. Earlier, Kurisu Makise had discussed with him the possibility of shifting into the CS100 world and had devised a strategy to return to the Steins Gate.
According to Kurisu Makise's hypothesis, the CS100 world contains a total of world lines, numbered from to . Kurisu Makise thus created a monitoring machine that can observe the layout of the world lines and the -bit singularity value of each world line. Each world line also has an outgoing edge , this edge would cause effect to connecting world line. Initially, .
At time , an event will occur, indicating that the -th world line will change its edge (note that may be equal to ). Moreover, affected by this, the singularity values of the world lines reachable from the -th world line will change. Assuming the singularity value of the -th world line is , the singularity value of the world line , which is reached after passing one outgoing edge from , will be XORed with the result of cyclically shifted left once. And the singularity value of the world line , which is reached after passing twice through outgoing edge from , will be XORed with the result of cyclically shifted left twice. In general, the singularity value of the world line reached after passing outgoing edges will be XORed with the result of cyclically shifted left times. This process will terminate either after encountering a world line whose singularity value has been modified by this event or after shifting into world line itself (this event would not change singularity value ).
A cyclic shift left is defined as shifting a binary number to the left once, with the highest bit of the binary number moving to the lowest bit, and the other bits moving one place to the left. For example, if $s=\underbrace{(10101...0110)_2}_{\text{32 bits in total}}$, the result of shifting once is $\underbrace{(01010...1101)_2}_{\text{32 bits in total}}$, and the result of shifting twice is $\underbrace{(10100...1010)_2}_{\text{32 bits in total}}$.
Rintaro Okabe needs to reach the world line with the smallest singularity value to trigger the Steins Gate. Now, Rintaro Okabe has foreseen the occurrence of the next events through the machine and has already calculated the final destination.
Input Format
The first line contains two integers , separated by a space, indicating there are world lines and events occurring in sequence.
The second line contains integers , which is a -bit unsigned integer, representing the initial singularity values of the world lines.
The next lines each contain two integers , , indicating the changes in the world lines.
Output Format
Output two integers on two lines, representing the world line with the smallest final singularity value and its singularity value . If there are multiple world lines with the smallest singularity value, output the one with the smallest number.
6 5
1 2 3 4 5 6
1 1
2 5
3 5
6 2
2 1
3
3
Sample 1 explaination:
We use to denote bitwise xor, to denote cyclic left shift.
After , nothing change.
After , ,
After , ,
After , ,
After , ,
10 0
3 2 10 3 1 9 1 2 4 22
5
1
3 5
3 2 1
1 2
2 3
3 1
3 3
1 3
1
17
EL PSY KONGROO