Under construction

Still being built. Things may change

Dynamic Convex Hull

Time limit4sMemory limit512 MB

Summary
Maintain a set of functions (x-a)^4+b under insertions and deletions, and report the minimum value at each queried point x.
Level

Hard9 of 10

Topics
Geometry, Segment tree, Divide and conquer
Solved
No attempts yet

Problem

First, consider a classical related algorithm. You are given nn functions f1(x),f2(x),…,fn(x)f_1(x), f_2(x), \dots, f_n(x), where fi(x)=aix+bif_i(x)=a_i x+b_i. To find the minimum value of fi(x)f_i(x) over all ii for a fixed parameter xx, you only need to find the corresponding function on the convex hull.

Now you are given nn functions f1(x),f2(x),…,fn(x)f_1(x), f_2(x), \dots, f_n(x), where fi(x)=(x−ai)4+bif_i(x)=(x-a_i)^4+b_i. You need to perform mm operations. Each operation has one of the following forms:

  • "1 aa bb" (1≤a≤50 0001 \leq a \leq 50\,000, 1≤b≤10181 \leq b \leq 10^{18}): Add a new function fn+1(x)=(x−a)4+bf_{n+1}(x)=(x-a)^4+b, then change nn into n+1n+1.
  • "2 tt" (1≤t≤n1 \leq t \leq n): Delete the function ft(x)f_t(x). Each function is deleted at most once.
  • "3 xx" (1≤x≤50 0001 \leq x \leq 50\,000): Query the minimum value of fi(x)f_i(x) over all 1≤i≤n1 \leq i \leq n whose function fi(x)f_i(x) has not been deleted yet.

Input

The first line contains a single integer TT (1≤T≤51 \leq T \leq 5), the number of test cases. Each test case is described as follows.

The first line contains two integers nn and mm (1≤n,m≤100 0001 \leq n, m \leq 100\,000), the number of functions and the number of operations.

Each of the following nn lines contains two integers aia_i and bib_i (1≤ai≤50 0001 \leq a_i \leq 50\,000, 1≤bi≤10181 \leq b_i \leq 10^{18}), which define the ii-th function fi(x)f_i(x).

Each of the next mm lines describes one operation in the format shown above.

Output

For each query, print a single line containing the minimum value of fi(x)f_i(x). If there are no functions, print "-1" instead.

Examples1

  1. Example 1

    Input
    1
    2 8
    3 9
    6 100
    3 4
    2 1
    3 4
    1 1 1
    3 4
    2 2
    2 3
    3 4
    
    Expected output
    10
    116
    82
    -1