#P5678. [GZOI2017] 河神
[GZOI2017] 河神
Description
From the choices given by the River God, Shlw got inspiration for an algebra problem that he failed back then.
But now he hopes you can help solve it, because he is busy searching for pony resources.
Given the recurrence relations of sequences , , and , find the -th term of the sequence .
The recurrence is:
$$A_n=\begin{cases}a_n & 0 \le n < K \\ \bigoplus_{0 \le t < K} (A_{n-K+t} \otimes b_t) & n \ge K \end{cases}$$Here, denotes the AND operation, and denotes the OR operation.
Input Format
The first line contains two positive integers and .
The second line contains non-negative integers separated by spaces, representing .
The third line contains non-negative integers separated by spaces, representing .
Output Format
One line with one integer, representing .
10 5
2 3 5 7 12
23 45 2 4 8
15
Hint
【Sample Explanation】
From to , they are respectively: .
【Constraints】

【Postscript】
Later, Pinkie Pie secretly came to Shlw’s home. She took this problem back to test Apple Jack, so Apple Jack gained the ability to travel the multiverse by eating apples like crazy.
Translated by ChatGPT 5
京公网安备 11011102002149号