#P9086. 「SvR-2」令人为难的区间操作问题
「SvR-2」令人为难的区间操作问题
Background
Problem Number:
As everyone knows, range operation problems usually ask for values like range sums, maximums, and so on. But today, Little F has an unusual request.
Problem Description
Little F is studying the Fibonacci sequence. To his surprise, by slightly modifying the definition of the Fibonacci sequence , he obtains the sequence:
Note that the sequence is periodic, with the smallest positive period .
Please note the difference between this sequence and the double gamma function in mathematics that uses the same symbol.
Little F finds a sequence of length . Each time, he performs the following operation:
- Choose two integers such that .
- For each satisfying , add to .
- Record the length of the chosen interval for this operation (i.e. the -th operation) as .
He performs a total of operations. Let the resulting sequence after all operations be , and let .
Unfortunately, Little F loses both and the sequence . He only remembers and the sequences .
Now, he wants you to determine the parity of , that is, the value of modulo .
Input Format
This problem contains multiple test cases.
The first line contains an integer , the number of test cases.
The next lines describe the test cases. For each test case:
- The first line contains an integer .
- The second line contains integers describing the sequence .
- The third line contains integers describing the sequence .
It is guaranteed that sequence can be transformed into sequence by some number of operations.
Output Format
For each test case, output one line with a single number, which is modulo .
1
4
1 2 3 4
2 4 3 4
1
Hint
Explanation of Sample 1
Note that the following operations may have been performed:
- In the -st operation, choose , then the sequence becomes $[1,{\underline{\color{red}\textbf{3}}},{\underline{\color{red}\textbf{4}}},4]$. At this time, .
- In the -nd operation, choose , then the sequence becomes $[{\underline{\color{red}\textbf{2}}},{\underline{\color{red}\textbf{4}}},{\underline{\color{red}\textbf{3}}},4]$. At this time, .
Then , which is odd. Therefore, .
Constraints and Conventions
This problem uses bundled testdata.
$$\newcommand{\arraystretch}{1.5} \begin{array}{c|c|c|c}\hline\hline \textbf{Subtask} & \bm{\sum n\le} & \textbf{Special Properties} & \textbf{Score} \\\hline \textsf{1} & \le 10 & a_i,b_i\le 10^9 & 10 \\\hline \textsf{2} & \le 10^3 & a_i,b_i\le 10^9 & 20 \\\hline \textsf{3} & \text{No special constraints} & a_i,b_i\le 10^9 & 20 \\\hline \textsf{4} & \text{No special constraints} & a_i\le b_i & 20 \\\hline \textsf{5} & \text{No special constraints} & - & 30 \\\hline\hline \end{array}$$For of the testdata, , , .
Within a single test point, it is guaranteed that .
Notes
The sequence has the following recurrence:
$$\digamma(x)= \begin{cases} 1,&x\le 2\\ -1,&x=3\\ \digamma(x-1)-\digamma(x-2)+\digamma(x-3),&x>3. \end{cases}$$Translated by ChatGPT 5