#P11891. [XRCOI Round 1] B. 稻花香里说丰年
[XRCOI Round 1] B. 稻花香里说丰年
Background
Add a more formal problem statement.
Talking about a good harvest amid the fragrance of rice flowers, listening to a chorus of frogs.
Problem Description
In a rice field there are frogs of two types: and . They line up into two columns, and .
Genius_Star noticed these frogs, so he decided to split the two frog sequences into arbitrary segments with the same start and end positions. Define the neatness of a segment as:
Here, equals if proposition is true, otherwise .
Then the happiness value brought to Genius_Star by segment is:
where:
is the number of subsequences of type contained in interval of sequence .
is the number of subsequences of type contained in interval of sequence .
The happiness value of a segmentation plan is the sum of the happiness values of all its segments. You need to compute the sum of the happiness values over all segmentation plans.
Suppose the sequences are split into segments, and the -th segment is . The following must hold:
- .
- .
Two segmentation plans are different if and only if they have different numbers of segments, or there exists some such that .
Since Genius_Star cannot be too happy, you also need to take the answer modulo .
Formal statement
Given two sequences , define:
- as the number of positions in interval where .
- as the number of subsequences of type in interval of sequence .
- as the number of subsequences of type in interval of sequence .
- $W(l,r) = T(l,r) \times \Big(A(l,r) + B(l,r) \Big)$.
Here, a subsequence of type means selecting two elements from left to right in the interval (not necessarily contiguous), where the first number is and the second number is . Two subsequences are different if and only if the position of or the position of is different.
Now you need to split the two sequences into arbitrary segments with the same start and end positions, and compute the sum, over all splitting methods, of the total of all segments.
Since the answer may be very large, output it modulo .
Input Format
The first line contains two positive integers .
When , the values for this test are given directly:
- The next lines each contain two integers .
When , the values for this test will be generated in a special way:
- The second line contains five integers .
- The third line contains five integers .
Then satisfy:
$$f_i = (f_{i-2} \times x_1 + f_{i-1} \times y_1 + z_1) \bmod 2^{64}$$$$g_i = (g_{i-2} \times x_2 + g_{i-1} \times y_2 + z_2) \bmod 2^{64}$$Then:
- The value of is the -th bit from low to high in the binary representation of .
- The value of is the -th bit from low to high in the binary representation of .
The above generation method is only to reduce input size; the standard algorithm does not depend on it.
Output Format
Output one line with an integer , meaning the sum of the happiness values of all segmentation plans.
3 0
1 0
1 1
0 0
1
5 0
0 1
1 0
0 1
1 1
1 1
70
4 0
0 1
1 0
0 1
1 0
52
5 1
1 1 0 1 1
1 1 1 1 1
22
10000 1
1 1 0 1 1
1 1 1 1 1
559297012
Hint
Sample explanation #1:
Only when splitting as , we have .
Sample explanation #4:
We can obtain:
Thus:
Then:
So the answer is .
Constraints
This problem uses bundled tests.
Subtask is the sample and is worth points.
| Subtask ID | Special Property | Points | ||
|---|---|---|---|---|
| None | ||||
| None | ||||
Special property : .
Special property : there exists exactly one such that .
For of the testdata, it is guaranteed that $1 \le n \le 5\times 10^7,1 \le x_1,x_2,y_1,y_2,z_1,z_2,f_1,f_2,g_1,g_2 \le 10^{18}$.
Translated by ChatGPT 5