#P6301. 集合
集合
Problem Description
You need to maintain online a sorted set of natural numbers and support the following operations:
- Given a number , if is not in the set , then insert into .
- Given a number , if is already in the set , then delete from .
To prove that you are maintaining , you must answer the following queries during the operations:
- Output the value of the minimum element in . If , return
-1. - Output the value of the maximum element in . If , return
-1. - Output the number of elements in .
- Given a number , determine whether is in the set. If yes, return
1; otherwise, return0. - Given a number , let . Output the value of the maximum element in . If , return
-1. - Given a number , let . Output the value of the minimum element in . If , return
-1.
To prove that you maintain online, for all operations and queries after the first query, the actual parameter equals the parameter given in the input plus the return value of the previous query. That is, .
It is guaranteed that .
Initially, .
Input Format
The input has lines, where the meaning of is given below.
The first line contains two positive integers , where is the upper bound of the parameter in operations and queries, and is the total number of operations and queries.
The next lines each contain one or two natural numbers, representing one operation or one query. Each line is guaranteed to be in one of the following eight forms:
1 x', meaning perform operation .2 x', meaning perform operation .3, meaning answer query .4, meaning answer query .5, meaning answer query .6 x', meaning answer query .7 x', meaning answer query .8 x', meaning answer query .
Output Format
To avoid too much output, you only need to output one line with one integer, which is the sum of the return values of all queries.
4 13
1 0
1 1
1 3
1 3
3
7 0
7 2
8 3
4
2 0
4
6 2
5
8
Hint
Sample Explanation
The operations actually performed and the queries actually answered are as follows:
1 0
1 1
1 3
1 3
3 -> 0
7 0 -> -1
7 1 -> 0
8 3 -> 3
4 -> 3
2 3
4 -> 1
6 3 -> 0
5 -> 2
Therefore, the output is .
Constraints
| Test Point ID | Score | ||
|---|---|---|---|
For of the testdata, , , and .
Hint
The input size of this problem is large, so a faster input method is recommended.
denotes a value slightly smaller than , and guarantees that in the 7th operation is always well-defined.
Translated by ChatGPT 5