#P7386. 「EZEC-6」0-1 Trie

    ID: 8206 远端评测题 1500ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP组合数学逆元构造Lucas 定理

「EZEC-6」0-1 Trie

Background

000111\mathbf{000111}, this is the beauty contained in simplicity.

As everyone knows, tlx cannot handle strings.

Problem Description

Now tlx has nn 1\mathbf{1}'s and mm 0\mathbf{0}'s. You need to arrange them, but you must ensure that any two 1\mathbf{1}'s are not adjacent, and that the first position is 0\mathbf{0} and the last position is 1\mathbf{1}. Now put all strings that can be constructed onto a 0-1 Trie. How many nodes are needed?

Note: when counting nodes, do not count the initial empty root node; only count the nodes representing 0\mathbf{0} and 1\mathbf{1}.

In this problem, we assume characters are stored in nodes rather than on edges, but the basic idea of the Trie is unchanged.

Because the answer may be very large and there are many queries, please finally output the XOR sum of all query answers modulo 1888891318888913 (don’t worry, it is a prime). (The XOR sum itself is not taken modulo again.)

Input Format

The first line is a positive integer TT, representing the number of test cases.

In the next TT lines, each line contains two positive integers n,mn, m, representing the counts of 1\mathbf{1} and 0\mathbf{0} respectively.

Output Format

Output one integer in a single line, representing the XOR sum of all results.

1
2 4
15
2
3 5
114514 1919810
4487351

5
78 122
1000000 1000001
74859432 942432534
555555555 77777777 
6666666666 8888888888
12287990

Hint

[Sample Explanation #1]

We can see that all constructible strings are:

000101\mathbf{000101} 001001\mathbf{001001} 010001\mathbf{010001}

Construct the 0-1 Trie as shown:

A total of 1515 nodes are needed.

[Sample Explanation #2]

The answers to the two queries are 3434 and 44873174487317 respectively.


[Constraints and Hints]

Note: this problem uses bundled testdata. You will only get the score of a Subtask after you pass all test points within that Subtask.

The specific constraints are as follows:

Subtask 11 (10%10\%): T10T \leq 10, n,m5n, m \leq 5.

Subtask 22 (20%20\%): T10T \leq 10, n,m1×103n, m \leq 1\times 10^3.

Subtask 33 (30%30\%): T10T \leq 10, n,m5×105n, m \leq 5\times 10^5.

Subtask 44 (40%40\%): no special restrictions.

For 100%100\% of the testdata: 1T2×1061 \le T \le 2\times10^6, 1n,m5×10181 \le n, m \le 5\times 10^{18}.

The input size of this problem is large. It is recommended to use a fast input method and pay attention to the impact of constant factors on program efficiency.


A 0-1 Trie is a special kind of Trie with only two characters, 0,1\mathbf{0,1}.

If you are not familiar with Trie, you can refer to: OI Wiki--Trie.

Translated by ChatGPT 5