#P5302. [GXOI/GZOI2019] 特技飞行

[GXOI/GZOI2019] 特技飞行

Description

In the year 90129012, the aviation base of City Z plans to hold an aerobatic flight show. The show venue can be seen as a 2D Cartesian coordinate system, where the xx-coordinate represents the horizontal position and the yy-coordinate represents the flight altitude.

In the initial plan, these nn aircraft will first fly to the starting line x=xstx = x_{st}. For aircraft ii, its altitude at the start is yi,0y_{i,0}. Their destination is the ending line x=xedx = x_{ed}, where aircraft ii should be at altitude yi,1y_{i,1}. Therefore, each aircraft can be viewed as a point in the coordinate system, and its route is a line segment starting from (xst,yi,0)(x_{st}, y_{i,0}) and ending at (xed,yi,1)(x_{ed}, y_{i,1}), as shown below.

aerobatics1.png

All nn aircraft depart at the same time and always maintain a constant ground speed. Therefore, for any two intersecting routes (segments), the two corresponding aircraft will 반드시 reach the intersection point at the same time—this is the moment they perform an aerobatic stunt. They will bank their wings and perform a close “pass-by” stunt, and then continue along their own routes.

The aviation base has also recently developed a new stunt called “head-on swap”. When two aircraft reach the intersection point, the one that was descending immediately starts climbing, while the one that was climbing performs a flip. The two aircraft pass the intersection point one above the other, belly to belly, also at a very close distance, and then swap their remaining routes.

We do not need to care how these stunts are physically achieved. Aircraft are still treated as points. Under these two stunts, the route changes are shown below (yi,1y_{i,1}' denotes the new ending altitude of aircraft ii after swapping routes). It is easy to see that “head-on swap” turns their routes into polylines and keeps their relative order in the yy-coordinate; while “pass-by” changes their relative order in the yy-coordinate.

aerobatics2.png

Now, the visiting guests提出 a strict requirement: at the ending line x=xedx = x_{ed}, when sorting by altitude, the relative order of the nn aircraft must be the same as the relative order at x=xstx = x_{st}. The guests also assign difficulty coefficients aa and bb to the “head-on swap” stunt and the “pass-by” stunt, respectively. Each “head-on swap” gives a score of aa, and each “pass-by” gives a score of bb.

In addition, there are kk guests. Guest ii stays in a hot-air balloon at position (pi,qi)(p_i, q_i) and has an observation range rir_i, so they can observe all stunts within the region xpi+yqiri|x - p_i| + |y - q_i| \le r_i.
If a stunt at some intersection point is observed by one or more guests, an extra bonus score of cc is obtained.
Note: Whether or not a stunt is observed, it still earns the score aa or bb.

The figure below shows, for the 44 routes and 44 intersections in the first figure, one arrangement that meets the requirement: it includes 22 “head-on swap” stunts, 22 “pass-by” stunts, and 33 stunts are observed, for a total score of 2a+2b+3c2a + 2b + 3c. For easier viewing, the intersections where “head-on swap” occurs are drawn slightly separated.

aerobatics3.png

In this story, you are the planner of City Z’s aviation base. You can decide, at each intersection point, whether to perform “head-on swap” or “pass-by”. You are required, while ensuring the guests’ requirement, to compute the minimum and maximum total scores that the whole aerobatic show can achieve.

Input Format

The first line contains six non-negative integers n,a,b,c,xst,xedn, a, b, c, x_{st}, x_{ed}, representing the total number of routes (segments), the score for the “head-on swap” stunt, the score for the “pass-by” stunt, the extra bonus for being observed, the xx-coordinate of the starting line, and the xx-coordinate of the ending line.

The second line contains nn non-negative integers yi,0y_{i,0}. The ii-th number is the yy-coordinate of the start point of route ii. It is guaranteed that they are given in increasing order, i.e. yi,0<yi+1,0y_{i,0} < y_{i + 1,0}.

The third line contains nn non-negative integers yi,1y_{i,1}. The ii-th number is the yy-coordinate of the end point of route ii.

The fourth line contains a non-negative integer kk, the number of guests.

The next kk lines each contain three non-negative integers pi,qi,rip_i, q_i, r_i, representing the xx-coordinate, yy-coordinate, and observation range of guest ii.

The input also imposes some limits on the total number of intersection points of all routes (segments) between the lines x=xstx = x_{st} and x=xedx = x_{ed}. See “Constraints and Hint” for details.

Output Format

Output only one line containing two integers: the minimum and maximum possible total scores of the whole aerobatic show, separated by a space.

4 1 2 3 1 6
1 2 3 4
4 1 3 2
2
3 3 1
5 2 2
13 15
10 73 28 13 0 100
2 9 16 25 29 34 43 46 52 58
8 25 35 52 41 5 16 3 19 48
5
46 40 1
37 27 5
67 34 1
65 28 4
29 38 1
989 1619

Hint

Sample 1 Explanation

The routes in this sample are exactly those shown in the figure in the statement, except that the guests’ positions are slightly different.
The minimum-score plan uses the “head-on swap” stunt at all intersection points, with score 4a+3c=134a + 3c = 13.
The maximum-score plan is the same as the one shown in the figure in the statement, with score 2a+2b+3c=152a + 2b + 3c = 15.

Constraints

No three or more segments intersect at the same point.
All coordinates and rir_i are non-negative integers not exceeding 5×1075 \times 10^7.
yi,0<yi+1,0y_{i,0} < y_{i + 1,0}, and all yi,1y_{i,1} are distinct.
xst<pi<xed,1a,b,c103x_{st} < p_i < x_{ed}, 1 \le a, b, c \le 10^3.

Test Point ID Scale of n,kn, k Scale of number of intersections Notes
11 n,k15n, k \le 15 40\le 40 None
22
33
44
55 n30,000,k100n \le 30,000, k \le 100 200,000\le 200,000
66
77
88
99 n,k100,000n, k \le 100,000 500,000\le 500,000 a=ba = b
1010
1111
1212
1313 n,k50,000n, k \le 50,000 250,000\le 250,000 None
1414
1515
1616
1717 n,k100,000n, k \le 100,000 500,000\le 500,000
1818
1919
2020

Translated by ChatGPT 5