#P8929. 「TERRA-OI R1」别得意,小子

「TERRA-OI R1」别得意,小子

Background

Midway through the battle, the blue-purple sky suddenly turned into a vast black mass. Some purple shells on the God Devourer began to fall off, turning into smaller pythons. From the moment they appeared, these little guys charged at you recklessly. After you had just cleared them out, a bloody huge mouth suddenly emerged from the mist, as the God Devourer rushed toward you......

Problem Description

You are given a piecewise function with nn segments. Each segment may be a linear function or a quadratic function. There are qq queries. Each query asks either for the value of yy when x=kx=k, or for how many intersection points the line y=ky=k has with the function.

Input Format

The first line contains two integers n,qn,q separated by spaces, representing the number of segments and the number of queries.

From line 22 to line n+1n+1, first read lil_i and rir_i, meaning that the domain of this segment is (li,ri](l_i,r_i] (it is guaranteed that l1=0l_1=0, and i[1,n1],ri=li+1\forall i\in [1,n-1],r_i=l_{i+1}). Then read one of the following two cases:

  • 11 kk bb, meaning this interval is a linear function y=kx+by=kx+b (it is guaranteed that k0k\ne 0).
  • 22 aa bb cc, meaning this interval is a quadratic function y=ax2+bx+cy=ax^2+bx+c (it is guaranteed that a0a\ne 0).

From line n+2n+2 to line n+q+1n+q+1, each line contains two integers op,kop,k separated by spaces:

  • If op=1op=1, output the value of yy when x=kx=k (it is guaranteed that k(0,rn]k\in (0,r_n]).
  • If op=2op=2, output how many intersection points the line y=ky=k has with the whole piecewise function within the range (0,rn](0,r_n].

Output Format

There are qq lines in total. Each line contains one integer, the answer to the corresponding query.

3 4
0 3 1 1 2
3 6 2 1 -2 1
6 10 1 1 0
1 4
2 5
2 114514
2 2
9
2
0
0
6 8
0 4 2 1 -4 0 
4 6 1 2 -10 
6 11 1 1 -19 
11 19 2 -1 -30 559 
19 29 1 1 -58 
29 38 1 1 -68 
1 11
2 4
2 -1
1 21
2 -5
2 2
1 34
2 1

-8
1
4
-37
1
2
-34
2

Hint

Sample Explanation #1

The three segments are y=x+2y=x+2, y=x22x+1y=x^2-2x+1, and y=xy=x.

For x=4x=4, substituting into the second segment gives the result 99.

The line y=5y=5 intersects the first and second segments, and each has exactly one intersection point, so the result is 22.

Obviously, the line corresponding to the third query does not intersect the function.

Although the line in the fourth query intersects the first segment at x=0x=0, 00 is not in that segment's interval, so it is discarded.


Constraints

This problem uses bundled testdata.

Subtask Score n,qn,q\le limit
11 1010 100100 None
22 1515 10310^3 rn5×103r_n\le 5\times 10^3
33 2020 2×1052\times 10^5 No query of type 22
44 2525 No quadratic function
55 3030 None

For 100%100\% of the testdata, 1n,q2×1051\le n,q\le 2\times 10^5, 0li,ri1090\le l_i,r_i\le 10^9, and i[1,n],ri>li\forall i\in [1,n],r_i>l_i.

All function coefficients are within the storage range of 64-bit signed integers, and the computation results, as well as the maximum and minimum values of any term in each function expression, will not exceed the storage range of 64-bit signed integers. All query parameters are within the range of 32-bit signed integers.

(i.e. 4×1018k,a,b,c4×1018-4\times 10^{18}\le k,a,b,c\le 4\times 10^{18}, 109x109-10^9\le x\le 10^9)


Hint

When using floating-point numbers, it is recommended to use long double to avoid precision issues.

upd: A set of hack testdata has been added. If you do not pass it, it will show as "Unaccepted 100pts".

Translated by ChatGPT 5