#P9216. [入门赛 #11] 写大作业 (Hard Version)
[入门赛 #11] 写大作业 (Hard Version)
Background
The difference from the Easy Version is that the input consists of sequences rather than strings, the input/output format is different, and the data scale is different.
Problem Description
Fusu has been awake for hours to write a Theory of Computation final project.
To be able to sleep sooner, Fusu found references. The -th reference is a sequence , and she plans to combine these references.
Specifically, there are two types of operations:
1 x y: Concatenate the whole sequence to the end of , then delete .2 x y: Query whether and are similar.
We guarantee that after an operation 1 x y occurs, the sequence will not appear in any subsequent operations. That is, operation type occurs at most times.
The definition of similar is: for two sequences and , if there exists a way to reorder such that the reordered is equal to , then and are called similar.
For example, suppose , , and . After executing 1 1 2, is deleted, and , while . Continuing with 2 2 3, since we can reorder into , and are similar.
Note that operation type does not actually modify any sequence.
Input Format
The first line contains two integers, denoting the number of references and the number of operations .
The next lines each describe a sequence. Line describes :
the first number is , the length of , followed by numbers describing the sequence .
The next lines each contain three integers , with meanings as described in the Description.
Output Format
To avoid excessive output, output one line with one integer, denoting the bitwise XOR of the operation indices of all queries whose answer is the two sequences are similar.
Operation indices start from . Both types of operations increase the index by . You may refer to the sample explanation to understand the output format.
4 5
2 1 2
2 3 4
4 1 2 3 4
4 1 2 3 3
1 1 2
2 2 3
2 3 4
2 2 4
2 3 2
7
Hint
Sample Explanation
There are five operations in total. Their indices and answers are as follows:
| Index | Operation | Answer |
| :-: | :-: | :-: |
| | 1 1 2 | Not a query operation |
| | 2 2 3 | Similar |
| | 2 3 4 | Not similar |
| | 2 2 4 | Not similar |
| | 2 2 3 | Similar |
We can see that the operation indices of queries answered the two sequences are similar are and . Their bitwise XOR is . Therefore, the output is .
Constraints and Notes
For all test points, it is guaranteed that , , , . All elements in the sequences are non-negative integers not exceeding .
The testdata guarantees that the elements are generated in the following way: for a sequence, an upper bound on the element values is specified, then integers are generated uniformly at random in as the sequence . Note that is not necessarily .
Translated by ChatGPT 5