← 返回 walmartlabs 的题目列表Range Module
类型:online_judge
Problem: Range Module
Implement a RangeModule that tracks a set of half-open intervals on the real line. It supports the following operations:
addRange(left, right): Add the half-open interval [left, right) to the tracked set. Overlapping or adjacent tracked intervals should be merged.
queryRange(left, right): Return true if the entire interval [left, right) is currently tracked; otherwise return false.
removeRange(left, right): Remove the portion covered by [left, right) from the tracked set. An existing interval may be shortened or split.
Input Format
The first line contains the number of operations q.
Each following line contains one operation:
add left right
query left right
remove left right
For every query operation, print true or false on its own line.
Example
Input:
6
add 10 20
remove 14 16
query 10 14
query 13 15
query 16 17
query 10 20
Output:
true
false
true
false
Constraints
1 <= q <= 10^5
0 <= left < right <= 10^9
All intervals are half-open: [left, right).
Target O(log n + k) time per operation, where n is the number of stored endpoints and k is the number of endpoints merged or removed by the operation.
Example
Input
6
add 10 20
remove 14 16
query 10 14
query 13 15
query 16 17
query 10 20
Output
true
false
true
false