#P11695. Interval Multiset Maintenance and Exact Cover Query
Interval Multiset Maintenance and Exact Cover Query
Interval Multiset Maintenance and Exact Cover Query
You are given two integers \(n\) and \(m\). We maintain a multiset (i.e. a set that allows duplicate intervals) of intervals on the number line [1, n) (with the half-open interval notation) that is initially empty. You need to process \(m\) operations. There are three types of operations:
- Insertion: Given two integers \(l\) and \(r\) with \(1 \le l < r \le n\) insert the interval \([l, r)\) into the multiset.
- Deletion: Given an integer \(t\), remove the interval that was inserted in the \(t\text{-th}\) insertion operation. It is guaranteed that this interval has not been removed yet.
- Query: Given an interval \([l, r)\), determine whether there exists a subset of the current multiset of intervals such that the union of the chosen intervals is exactly \([l, r)\). Note that if an interval in the subset extends outside \([l, r)\), then the union will not be exactly \([l, r)\). Thus, only the intervals completely contained in \([l, r)\) can be chosen.
For the query, you can use a greedy strategy: filter the active intervals that are completely within \([l, r)\), sort them by their starting point and then try to cover the entire interval \([l, r)\) without gaps. If you can cover from \(l\) to \(r\) exactly, output YES
; otherwise, output NO
.
inputFormat
The first line contains two integers \(n\) and \(m\) (\(1 \le n \le 10^9\); \(1 \le m \le 10^5\)), representing the length of the number line and the number of operations respectively.
Each of the next \(m\) lines describes an operation in one of the following formats:
- For an insertion operation:
1 l r
(inserts the interval \([l, r)\)). - For a deletion operation:
2 t
(deletes the interval inserted in the \(t\)-th insertion operation). - For a query operation:
3 l r
(queries whether there exists a subset of intervals whose union is exactly \([l, r)\)).
outputFormat
For each query operation (operation type 3), output a line containing either YES
if there exists a subset of active intervals whose union is exactly \([l, r)\), or NO
otherwise.
sample
10 6
1 1 3
1 3 5
1 5 10
3 1 10
2 2
3 1 10
YES
NO
</p>