← 返回 openai 的题目列表Snapshot Set
类型:online_judge
Implement a snapshot-enabled set of integers.
Maintain an initially empty set and process the following operations in order:
ADD x: Add integer x to the current set. If it already exists, do nothing.
REMOVE x: Remove integer x from the current set. If it does not exist, do nothing.
SNAP: Create an immutable snapshot of the current set and return its snapshot ID. Snapshot IDs start from 0 and increase sequentially.
CONTAINS sid x: Determine whether x belongs to snapshot sid.
SIZE sid: Output the number of elements in snapshot sid.
Changes made after a snapshot must not affect that snapshot.
Input Format
The first line contains an integer Q, the number of operations.
Each of the following Q lines contains one operation listed above.
Output Format
For every SNAP, output the newly created snapshot ID.
For every CONTAINS, output true or false.
For every SIZE, output the size of the specified snapshot.
Constraints
1 <= Q <= 2 * 10^5
x is a signed 32-bit integer.
Every queried sid is guaranteed to refer to an existing snapshot.
Example
Input:
10
ADD 5
ADD 7
SNAP
REMOVE 5
SNAP
CONTAINS 0 5
CONTAINS 1 5
SIZE 0
SIZE 1
SNAP
Output:
0
1
true
false
2
1
2
Example
Input
10
ADD 5
ADD 7
SNAP
REMOVE 5
SNAP
CONTAINS 0 5
CONTAINS 1 5
SIZE 0
SIZE 1
SNAP
Output
0
1
true
false
2
1
2