#P16458. [UOI 2026] mex plus
[UOI 2026] mex plus
题目描述
From each pair, you need to choose one number for array and the other number for array . That is, for each pair , one of the following two choices can be made:
- add to array and to array ;
- add to array and to array .
After choices are made for all pairs, arrays and will have the same length.
For an array , let denote the smallest non-negative integer that does not appear in array . For example, if then , because numbers , , and appear in the array, while number does not. If then , because number does not appear in the array.
You need to maximize
After the initial set of pairs, queries are given. Each query either adds one pair to the set or removes one pair from the set. After each query, you need to find again the maximum possible value of for the current set of pairs.
It is important that after each query, you may choose the order of numbers in all pairs again. That is, the previous choice does not restrict the next answers.
输入格式
The first line contains two integers and $(1 \le n \le 2 \cdot 10^5, 0 \le q \le 2 \cdot 10^5)$ --- the initial number of pairs and the number of queries.
The next lines contain the initial pairs. The -th of these lines contains two integers and .
The next lines contain the queries. Each query has one of the following formats: or where .
The query means that the pair is added to the set.
The query means that one pair is removed from the set. It is guaranteed that at the moment of such a query, there exists at least one such pair in the set.
输出格式
Print integers.
The first integer is the maximum value of $\operatorname{mex}(A) + \operatorname{mex}(B)$ for the initial set of pairs.
Then, after each query, print the maximum value of $\operatorname{mex}(A) + \operatorname{mex}(B)$ for the current set of pairs.
Print each answer on a separate line.
5 1
0 1
0 2
1 1
4 5
2 3
+ 4 5
8
9
5 0
1 1
1 1
1 1
1 1
0 0
4
5 0
1 2
2 3
3 4
4 5
5 6
0
5 0
2 2
3 3
0 1
3 4
0 10
6
5 0
1 3
4 5
0 9
0 0
5 6
3
提示
In the first example, for the initial set of pairs it is optimal to choose, for example, , . Then , , and the sum is . After adding the pair , one can, for example, choose , , then , , and the sum is .
In the second example, the multiset of values is . It is optimal, for example, to choose , . Then , and the sum is .
In the third example, none of the values is equal to , so no choice can make or . Therefore, , and the sum is .
In the fourth example, it is optimal, for example, to choose , . Then , , and the sum is .
In the fifth example, it is optimal, for example, to choose , . Then , , and the sum is .
Scoring
- ( points): , ;
- ( points): for all initial pairs, and for all queries;
- ( points): for all initial pairs, and for all queries;
- ( points): , ;
- ( points): ;
- ( points): all queries have the form ;
- ( points): all queries have the form ;
- ( points): at any moment, for any three pairs from the current set, if the first pair shares a number with the second pair, and the second pair shares a number with the third pair, then there exists a number that belongs to all three pairs;
- ( points): ;
- ( points): without additional constraints.