### Problem
Implement Skiplist yourself without using built-in libraries. It maintains a sorted multiset through linked-list layers. search(target) reports membership; add(num) inserts one occurrence; erase(num) removes one occurrence and reports success, or returns false without a change if absent. Duplicate values are allowed. Preserve the source average O(log(n)) operation and O(n) space goals.
```cpp
class Skiplist {
public:
Skiplist();
bool search(int target);
void add(int num);
bool erase(int num);
};
```
### Examples
**Example 1:**
```text
Input: construct Skiplist(); add(5); add(5); erase(5); search(5); erase(5); search(5)
Output: erase results true,true; search results true,false
Explanation: Each successful erase removes only one of the two copies.
```
**Example 2:**
```text
Input: construct Skiplist(); erase(0); add(0); search(0); erase(1)
Output: false,true,false
Explanation: Erasing an absent value leaves the structure unchanged, and0 is a permitted value.
```
### Constraints
- num and target are integers in `[0,20000]`.
- At most 50000 total calls are made to search, add and erase.
- Duplicates are allowed.
- The source calls for a manually implemented skip list with average logarithmic operations and linear space; no unsupported execution or randomness guarantee is asserted here.
### Contract considerations
Keep the constructor and search/add/erase methods. All nodes, links, predecessor searches and updates are hand-written. No map, set or library skip-list implementation substitutes for the required structure.
```hint Read the boundary condition
If two equal values were added, should one successful erase necessarily make search return false?
```
### Boundary reminders
Keep the constructor and search/add/erase methods. All nodes, links, predecessor searches and updates are hand-written. No map, set or library skip-list implementation substitutes for the required structure.
Overview: Implement a Duplicate-Aware Layered Skip List. Implement Skiplist yourself without using built-in libraries.
Implement Skiplist yourself without using built-in libraries. It maintains a sorted multiset through linked-list layers. search(target) reports membership; add(num) inserts one occurrence; erase(num) removes one occurrence and reports success, or returns false without a change if absent. Duplicate values are allowed. Preserve the source average O(log(n)) operation and O(n) space goals.
Input: construct Skiplist(); add(5); add(5); erase(5); search(5); erase(5); search(5)
Output: erase results true,true; search results true,false
Explanation: Each successful erase removes only one of the two copies.
Example 2:
Input: construct Skiplist(); erase(0); add(0); search(0); erase(1)
Output: false,true,false
Explanation: Erasing an absent value leaves the structure unchanged, and0 is a permitted value.
Constraints
num and target are integers in
[0,20000]
.
At most 50000 total calls are made to search, add and erase.
Duplicates are allowed.
The source calls for a manually implemented skip list with average logarithmic operations and linear space; no unsupported execution or randomness guarantee is asserted here.
Contract considerations
Keep the constructor and search/add/erase methods. All nodes, links, predecessor searches and updates are hand-written. No map, set or library skip-list implementation substitutes for the required structure.
Boundary reminders
Keep the constructor and search/add/erase methods. All nodes, links, predecessor searches and updates are hand-written. No map, set or library skip-list implementation substitutes for the required structure.