#P9870. [NOIP2023] 双序列拓展
[NOIP2023] 双序列拓展
Problem Description
A sequence is called an extension of another sequence if and only if there exists a sequence of positive integers such that, after replacing with copies of , we obtain the sequence . For example:
- is an extension of , with or .
- However, is not an extension of , and is not an extension of .
Little R gives you two sequences and . He wants you to find an extension of with length and an extension of with length , such that for any , we have . Since the sequences are too long, you only need to tell Little R whether such two sequences exist.
To prevent you from just guessing, Little R also gives additional queries. In each additional query, Little R will modify the values of some elements in and . For each new and , you need to make the above decision again.
The queries are independent. In each query, all modifications are applied to the original sequences.
Input Format
The first line contains four integers , representing the test point index, the length of sequence , the length of sequence , and the number of additional queries. For the samples, indicates that the sample has the same constraints as test point .
The second line contains integers , describing sequence .
The third line contains integers , describing sequence .
Next, groups of additional queries are given. For each group:
- The first line contains two integers and , representing the numbers of modifications to sequences and , respectively.
- The next lines each contain two integers , meaning setting to .
- The next lines each contain two integers , meaning setting to .
Output Format
Output one line containing a 01 sequence of length . The first element is the answer for the initial query, and the following elements are the answers for the additional queries in order. For each query, if there exist sequences and that satisfy the conditions, output 1; otherwise output 0.
3 3 3 3
8 6 9
1 7 4
1 0
3 0
0 2
1 8
3 5
1 1
2 8
1 7
1001
Hint
[Sample Explanation #1]
Since and are too long, we use ellipses to indicate repeating the last element until the sequence length reaches . For example, means that all elements after the third one are .
The following describes four queries in order. The first is the initial query, and the next three are additional queries:
- , . Take .
- , . It can be proven that no solution satisfies the requirement.
- , . It can be proven that no solution satisfies the requirement.
- , . Take .
[Sample Explanation #2]
This sample satisfies the constraints of test point .
[Sample Explanation #3]
This sample satisfies the constraints of test point .
[Sample Explanation #4]
This sample satisfies the constraints of test point .
[Sample Explanation #5]
This sample satisfies the constraints of test point .
[Constraints]
For all testdata, it is guaranteed that:
- .
- .
- .
- , and the sum of over all additional queries does not exceed .
- , , .
- For each additional query, all are pairwise distinct, and all are pairwise distinct.
| Test Point Index | Special Property | |
|---|---|---|
| No | ||
| Yes | ||
| No | ||
Special property: For each query (including the initial query and additional queries), it is guaranteed that , and is the unique minimum value in sequence , while is the unique maximum value in sequence .
Translated by ChatGPT 5