luogu#P4803. [CCO 2015] 太阳能飞行

[CCO 2015] 太阳能飞行

Background

Warning: abusing the judging system for this problem will result in your account being banned.

Problem Description

This problem is translated from CCO 2015 Day 1 T3 “Solar Flight”.

A new era of aviation is coming—the first solar-powered giant jet airliner is about to enter commercial service. However, the public has some safety concerns about cutting-edge technology, because the sunlight that powers the plane may be blocked by other objects in the sky. Therefore, some statistics and calculations must be done first to plan the first flight.

We consider a graph consisting of NN air routes from one city to another. An airplane can be regarded as a point. The sky it travels through can be modeled as a Cartesian coordinate system, where the XX axis represents the distance eastward from any point, and the YY axis represents altitude. We only consider xx values in the range [0,X][0,X], and all routes are straight line segments. Plane ii flies from (0,Ai)(0,A_i) to (X,Bi)(X,B_i). All AA values are distinct, and all BB values are also distinct. Planes move along their routes at an unknown, possibly non-constant speed, so at any time, a plane may be at any position on its route. However, it is known that planes never collide with each other, so if two routes intersect, the two planes will never reach the intersection point at the same time.

Each plane ii also has an interference value CiC_i, which represents how strongly a plane affects the solar energy absorption of planes below it.

The solar panels on each plane are very strange: they can only collect energy directly above the plane. This means that the sunlight a plane can absorb may be blocked by other planes that have the same xx value but a larger yy value. Specifically, the amount by which the absorbed sunlight is reduced equals the sum of the interference values of the planes blocking it.

Given this information and a distance constant KK, you need to answer QQ queries about possible effects on the solar panels. Query ii asks for the reduction in absorbed sunlight for plane PiP_i at some moment, where at that moment the plane’s xx value lies within [Si,Si+K][S_i,S_i+K].

Input Format

The first line contains four integers X,K,N,QX,K,N,Q, representing the maximum xx value considered, the distance constant, the total number of routes, and the number of queries.

The next NN lines each contain three integers Ai,Bi,Ci(1iN)A_i,B_i,C_i(1\le i \le N), representing plane ii’s starting yy value, ending yy value, and interference value.

The next QQ lines each contain two integers Pi,Si(1iQ)P_i, S_i(1\le i \le Q), meaning you should answer the question described above based on PiP_i and SiS_i.

Output Format

Output QQ lines. Each line contains one integer: the answer to query i(1iQ)i(1\le i \le Q).

12 4 3 3
1 4 5
2 2 3
6 3 6
2 1
1 8
3 0
11
6
0

Hint

A diagram of the flight routes is shown below.

CCO2015D1T3Pic1

Query 11 asks about plane 22 within the range [1,5][1,5]. When the plane is at x4x\le 4, it may be blocked by plane 33, but never by plane 11. However, when x>4x>4, it may be blocked by all other planes. Therefore, the answer to this query is the sum of the interference values of all other planes, which is 5+6=115+6=11.

For query 22, when x<10x<10, plane 11 may be blocked by plane 33, and when x10x\geq10, it will not be blocked by any plane. Therefore, it can only be affected by plane 33, so the result equals plane 33’s interference value 66.

For query 33, planes 11 and 22 cannot be directly above plane 33 unless xx reaches 1010. Therefore, the answer to this query is 00.

For 40%40\% of the testdata, Q1000Q\le 1000.

For 100%100\% of the testdata, 1N2000,1\le N\le 2000, 1KX,1\le K\le X, 1X,Ai,Bi,Ci109,1\le X,A_i,B_i,C_i\le 10^9, 0SiXK,0\le S_i\le X-K, 1Q8000001\le Q \le 800000

Translated by ChatGPT 5