Score : 500 points
Problem Statement
For a set S of pairs of non-negative integers, and a non-negative integer x, let fS(x) defined as fS(x)=(a,b)∈Smin∣∣x−a∣−b∣.
We have a set T of pairs of non-negative integers. Initially, T={(A,B)}.
Process Q queries. The i-th query gives you three non-negative integers ti, ai, and bi, and asks you to do the following.
- If ti=1, add to T the pair (ai,bi) of non-negative integers.
- If ti=2, print the minimum value of fT(x) for a non-negative integer x such that ai≤x≤bi.
Constraints
- 1≤Q≤2×105
- 0≤A,B≤109
- ti is 1 or 2.
- 0≤ai,bi≤109
- If ti=2, then ai≤bi.
- There is at least one query with ti=2.
- All values in the input are integers.
The input is given from Standard Input in the following format:
Q A B
t1 a1 b1
t2 a2 b2
⋮
tQ aQ bQ
Output
For each query with ti=2 in the given order, print the answer in its own line.
In the second query, T={(0,5),(3,11)}. For x=7, we have fT(7)=min{∣∣7−0∣−5∣,∣∣7−3∣−11∣}=min{2,7}=2. Similarly, fT(8)=3. Thus, the answer is min{2,3}=2.
In the fourth query, T={(0,5),(3,11),(8,2)}. In 8≤x≤9, fT(x) takes the minimum value fT(9)=1 at x=9.