#P9086. 「SvR-2」令人为难的区间操作问题

「SvR-2」令人为难的区间操作问题

Background

Problem Number: 45\textit{45}

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 FF, he obtains the ϝ\digamma sequence:

ϝ(x)={1,1,1,1,1,1,1,1,1,}\digamma(x)=\{1,1,-1,-1,1,1,-1,-1,1,\ldots\}

Note that the ϝ\digamma sequence is periodic, with the smallest positive period T=4T=4.

Please note the difference between this ϝ\digamma sequence and the double gamma function in mathematics that uses the same symbol.

Little F finds a sequence aa of length nn. Each time, he performs the following operation:

  • Choose two integers l,rl, r such that 1lrn1\le l\le r\le n.
  • For each ii satisfying lirl\le i\le r, add ϝ(il+1)\digamma(i-l+1) to aia_i.
  • Record the length of the chosen interval for this operation (i.e. the jj-th operation) as lenj=rl+1len_j=r-l+1.

He performs a total of mm operations. Let the resulting sequence after all operations be bb, and let sum=i=1mlenisum=\sum_{i=1}^m len_i.

Unfortunately, Little F loses both sumsum and the sequence lenlen. He only remembers nn and the sequences a,ba, b.

Now, he wants you to determine the parity of sumsum, that is, the value of sum\textbf{\textit{sum}} modulo 2\textbf2.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, the number of test cases.

The next 3T3\cdot T lines describe the test cases. For each test case:

  • The first line contains an integer nn.
  • The second line contains nn integers describing the sequence aa.
  • The third line contains nn integers describing the sequence bb.

It is guaranteed that sequence aa can be transformed into sequence bb by some number of operations.

Output Format

For each test case, output one line with a single number, which is sumsum modulo 22.

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 11-st operation, choose l=2,r=3l=2, r=3, then the sequence becomes $[1,{\underline{\color{red}\textbf{3}}},{\underline{\color{red}\textbf{4}}},4]$. At this time, len1=2len_1=2.
  • In the 22-nd operation, choose l=1,r=3l=1, r=3, then the sequence becomes $[{\underline{\color{red}\textbf{2}}},{\underline{\color{red}\textbf{4}}},{\underline{\color{red}\textbf{3}}},4]$. At this time, len2=3len_2=3.

Then sum=len1+len2=5sum=len_1+len_2=5, which is odd. Therefore, summod2=1sum\bmod 2=1.

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 100%100\% of the testdata, 1T1031\le T\le 10^3, 1n1051\le n\le 10^5, 1ai,bi10181\le a_i,b_i\le 10^{18}.

Within a single test point, it is guaranteed that n2×105\sum n\le 2\times 10^5.

Notes

The ϝ\digamma 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