luogu#P12102. [NERC2024] Knowns and Unknowns
[NERC2024] Knowns and Unknowns
题目描述
Two math professors have office hours on the same day. Students visit each professor to present their assignment solutions, one by one. For the whole semester, both professors established some fixed order of the students in which they should visit the professor. There are students denoted with integers from to . Each professor's order of students is a permutation of numbers from to .
Today only some of the students visited the university; let be the set of numbers that denote the students that were at the university today. All of the students from the set have visited both professors, and all of the students outside of the set haven't visited any professor.
Each of the professors made a list of the students they have talked with, in the same order the students have visited. Note that the list has to correspond to the order the professor has established, with the only difference that the students outside of the set are missing in it. It is the beginning of the year, so the professors didn't have a chance to get to know every student. So for the students that a professor knows, the list contains their identifier, but for those that the professor doesn't know, the list contains .
Consider an example: the first professor's order is , and the second professor's --- . The list made by the first professor today is , and the list made by the second professor is . Based on the lists, we can immediately see that three students have visited the university today. We can infer that the set was either or .
You are given two permutations --- the orders established by each professor; you are also given two lists that professors made today. Your task is to help the professors. Based on the provided data, determine for each student whether they definitely visited the university, definitely did not, or whether this cannot be determined. Note that professors could have confused the students, so there is a possibility that the given data is inconsistent.
输入格式
The first line contains a single integer () --- the number of test cases to solve.
Then the description of test cases follows.
The first line of the test case contains a single integer --- the number of students ().
The second line of the test case contains distinct integers --- the order established by the first professor, meaning that student comes first, and comes last ().
The third line of the test case contains distinct integers --- the order established by the second professor in the same format ().
The fourth line of the test case contains an integer --- the number of students that visited the university today ().
The fifth line of the test case contains integers --- the first professor's list. Each student appears in the list at most once ( or ).
The sixth line of the test case contains integers --- the second professor's list in the same format ( or ).
The total sum of in all test cases doesn't exceed 2000.
输出格式
For each test case, output a single string. If the given data is inconsistent, print a single word . Otherwise, print a string consisting of characters, the -th of which is if the -th student visited the university today, if the -th student didn't visit the university today, or if it cannot be determined.
2
4
1 2 3 4
3 2 4 1
3
1 -1 -1
3 -1 1
4
1 2 3 4
3 2 4 1
3
1 -1 2
3 -1 1
Y?Y?
Inconsistent
2
3
1 2 3
2 1 3
2
-1 2
-1 -1
3
1 2 3
3 2 1
2
1 3
2 -1
YYN
Inconsistent