#P15281. [MCO 2024] Max Partition
[MCO 2024] Max Partition
Description
:::epigraph After escaping from guns, Evirir the dragon is too tired to write a flavor text this time. :::
There is a positive integer . There are two lists of non-negative integers and , and all integers in the lists are between and (inclusive).
You can do the following operation zero or more times:
- Choose a list ( or ) and choose an integer in . Remove (one occurrence of) from and insert (one occurrence of) into (that is, the other list).
$\textbf{Additionally, after all operations, A\_0 and A\_1 must be nonempty.}$ A list can become empty after an operation, but after operations, both lists must be nonempty.
You wonder whether you can perform these operations such that the maximum value in each list is equal to a specific value. You also wonder whether the answer changes if you add or remove integers.
Process queries in order, where each query is in one of the following forms:
- Type 1 query:
- Add (one occurrence of) to .
- Type 2 query:
- Remove (one occurrence of) from .
- Type 3 query:
- Answer the question: Is it possible to make and after doing zero or more operations? Output or on a line.
Note: For Type 3 queries, you do not actually do any operations; you are only checking whether it is possible.
Here, means the largest integer in .
Input Format
The first line of the input contains three space-separated integers , , and (, , ), where and are the length of and , respectively.
The second line contains integers, the elements of . For each integer in , . This is a blank line if .
The third line contains integers, the elements of . For each integer in , . This is a blank line if .
The fourth line contains an integer (), the number of queries.
The next lines contain the queries in order. Each query consists of three space-separated integers and has one of the following forms:
- ( or , )
- ( or , )
- It is guaranteed that will contain when this query is given.
- ()
- It is guaranteed that the total number of integers in and is at least 2 when this query is given.
It is guaranteed that there is at least one Type 3 query.
Output Format
For each Type 3 query in the given order, if the answer is yes, output on a line. Otherwise, output on a line.
You may output each letter of and in any case. For example, and will be treated like ; and will be treated like .
5 4 10
3 4 6 7 0
1 3 7 8
11
3 7 3
3 0 1
3 6 9
3 4 4
3 7 8
2 1 3
1 0 5
1 1 2
3 4 4
3 0 10
3 7 5
YES
NO
NO
YES
YES
NO
NO
YES
10 0 8
2 2 3 3 3 1 5 5 5 6
4
3 2 6
3 6 2
3 5 3
3 3 5
YES
NO
YES
YES
0 0 10
5
1 1 4
1 1 6
2 1 4
1 0 4
3 4 6
YES
Hint
Note
For the first query (), we can do the following:
- Choose 8 from : Remove 8 from and insert into .
- Choose 7 from : Remove 8 from and insert into .
This results in and . The maximum element in and are 7 and 3 respectively as desired, so the answer is .
For the fourth query (), we can operate on 6 and 7 from and 7 and 8 from . This results in and .
For the fifth query (), the maximum elements in and are already 7 and 8 respectively, so no operation is needed.
After the sixth query (), . After the 7th and 8th queries ( and ), and .
This sample satisfies the constraints of Subtask 1 and 2. For the first query, we can remove one of the 2s in and insert into .
Note that both lists can be empty initially.
Scoring
Subtask 1 (17 points): . . All queries are Type 3 queries with .
Subtask 2 (9 points): . All queries are Type 3 queries with .
Subtask 3 (14 points): . All queries are Type 3 queries.
Subtask 4 (28 points): , . All queries are Type 3 queries.
Subtask 5 (21 points): All queries are Type 3 queries.
Subtask 6 (11 points): No additional constraints.
京公网安备 11011102002149号