#P2184. Distinct Mine Types in the Trench
Distinct Mine Types in the Trench
Distinct Mine Types in the Trench
There is a trench of length \(n\). SCV can plant a new type of mine (each update uses a distinct mine type that has not been planted before) in a given interval \([L, R]\). At times, FF may ask: in a given interval \([L', R']\), how many distinct mine types have been planted? A mine type is considered present in the interval if it has been planted in at least one position within that interval.
The operations are of two types:
- Update Operation:
0 L R
— plant a new mine type in the interval \([L, R]\). - Query Operation:
1 L R
— output the number of distinct mine types in the interval \([L, R]\). In other words, for each previously performed update with interval \([L_u, R_u]\), it is counted if \(L_u \le R\) and \(R_u \ge L\).
You are given \(n\) (the length of the trench) and \(q\), the total number of operations. Process the operations in the order given. For every query operation, output the number of distinct mine types that are present in the queried interval.
Note: Each update places a unique mine type, so you can simply count how many update intervals intersect the query interval.
inputFormat
The first line contains two integers \(n\) and \(q\): the length of the trench and the number of operations.
The next \(q\) lines each contain an operation in one of the following formats:
0 L R
: an update operation where a new mine type is planted in the interval \([L, R]\).1 L R
: a query operation asking for the number of distinct mine types in the interval \([L, R]\).
outputFormat
For each query operation, output a single integer on a new line representing the number of distinct mine types present in the specified interval.
sample
5 5
0 1 3
1 2 4
0 2 5
1 1 5
1 4 5
1
2
1
</p>