atcoder#ARC155B. [ARC155B] Abs Abs Function

[ARC155B] Abs Abs Function

Score : 500500 points

Problem Statement

For a set SS of pairs of non-negative integers, and a non-negative integer xx, let fS(x)f_S(x) defined as $\displaystyle f_S(x)=\min_{(a, b) \in S} \left| \left| x-a \right| - b \right|$.

We have a set TT of pairs of non-negative integers. Initially, T={(A,B)}T=\lbrace (A, B)\rbrace.

Process QQ queries. The ii-th query gives you three non-negative integers tit_i, aia_i, and bib_i, and asks you to do the following.

  • If ti=1t_i=1, add to TT the pair (ai,bi)(a_i, b_i) of non-negative integers.
  • If ti=2t_i=2, print the minimum value of fT(x)f_{T}(x) for a non-negative integer xx such that aixbia_i \leq x \leq b_i.

Constraints

  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 0A,B1090 \leq A,B \leq 10^{9}
  • tit_i is 11 or 22.
  • 0ai,bi1090 \leq a_i,b_i \leq 10^{9}
  • If ti=2t_i=2, then aibia_i \leq b_i.
  • There is at least one query with ti=2t_i=2.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

QQ AA BB

t1t_1 a1a_1 b1b_1

t2t_2 a2a_2 b2b_2

\vdots

tQt_Q aQa_Q bQb_Q

Output

For each query with ti=2t_i=2 in the given order, print the answer in its own line.

4 0 5
1 3 11
2 7 8
1 8 2
2 8 9
2
1

In the second query, T={(0,5),(3,11)}T=\lbrace(0, 5), (3, 11) \rbrace. For x=7x=7, we have $f_T(7)=\min \lbrace \left| \left|7-0\right|-5\right|, \left| \left|7-3\right|-11\right| \rbrace=\min \lbrace 2, 7 \rbrace=2$. Similarly, fT(8)=3f_T(8)=3. Thus, the answer is min{2,3}=2\min \lbrace 2, 3 \rbrace =2.

In the fourth query, T={(0,5),(3,11),(8,2)}T=\lbrace(0, 5), (3, 11), (8, 2) \rbrace. In 8x98 \leq x \leq 9, fT(x)f_T(x) takes the minimum value fT(9)=1f_T(9)=1 at x=9x=9.

2 1 2
1 2 3
2 2 6
0
20 795629912 123625148
2 860243184 892786970
2 645778367 668513124
1 531411849 174630323
1 635062977 195695960
2 382061637 411843651
1 585964296 589553566
1 310118888 68936560
1 525351160 858166280
2 395304415 429823333
2 583145399 703645715
2 97768492 218377432
1 707220749 459967102
1 210842017 363390878
2 489541834 553583525
2 731279777 811513313
1 549864943 493384741
1 815378318 826084592
2 369622093 374205455
1 78240781 821999998
2 241667193 243982581
26468090
3491640
25280111
9543684
0
22804896
20649370
19245624
4849993
484865