#P8862. 「KDOI-03」还原数据
「KDOI-03」还原数据
Problem Description
Little E is working on a classic problem:
Given a sequence of length and operations, there are types of operations:
- : For all , set .
- : For all , set .
The task is to output the final sequence after all operations are finished.
Little E quickly wrote some code and submitted it, but then found that, due to cosmic rays, the input data had some minor issues. Specifically, for all type operations, the given was lost. That is, in the input data, every type operation only remains as . The output data has no problem. Little E now wants to restore the original input data from the remaining data. Please help him complete this task.
Of course, there may be multiple valid original inputs. You only need to find any one of them. The testdata guarantees that a solution exists.
Input Format
Read from standard input.
This problem has multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case, the first line contains two non-negative integers .
The second line contains integers, the initial sequence .
The next lines each contain one operation, in the form or .
The next line contains integers, the final sequence .
Output Format
Output to standard output.
This problem uses a Special Judge.
For each test case, suppose there are type operations in total. Output one line with integers. The -th integer represents the value of given in the -th type operation.
You must ensure that .
1
5 3
1 2 3 4 5
2 3 5
1 3 4 2
2 1 1
20 2 5 6 5
3 20
Hint
[Sample 1 Explanation]
All valid outputs must satisfy: the -st number , and the -nd number is exactly .
[Sample 2]
See restore/restore2.in and restore/restore2.ans in the contestant files.
[Sample 3]
See restore/restore3.in and restore/restore3.ans in the contestant files.
[Constraints]
Let be the number of type operations in one test case. Let be the sum of all within one test point, and be the sum of all within one test point.
For of the testdata, , and .
For of the testdata, , and .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , , , , , and .
[Checker]
The sample files for this problem are large and cannot be downloaded as attachments. Please view them in the contestant files.
To make testing easier, we provide a checker.cpp file in the directory. You can compile it and use it to check your output file. Note that it is not exactly the same as the checker used in the final judging, and you do not need to and should not care about the specific code details.
The compile command is:
g++ checker.cpp -o checker -std=c++14
Usage:
./checker <inputfile> <outputfile> <answerfile>
The checker may return one of the following statuses:
- : Your output is completely correct.
- : Your output is wrong on test case .
[Hint]
The input and output size of this problem is large, so faster I/O methods are recommended.
A warm reminder from the KDOI problem setters: if you do not clear arrays between test cases, you may get zero points and cry for two lines.
Translated by ChatGPT 5