#P15555. [CCPC 2025 哈尔滨站] 比赛

    ID: 17476 远端评测题 5000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>2025Special JudgeCCPC哈尔滨

[CCPC 2025 哈尔滨站] 比赛

Problem Description

The Cook Chicken Potato Contest is one of the most famous competitions in the chef world. The venue always provides kk stoves, and the organizer Little QQ will divide the contestants into kk teams with the same number of people.

To test teamwork among contestants and make the contest more exciting, Little QQ will arrange the teams so that the skill gaps among contestants in the same team are as large as possible. Suppose the contestants' skills are a1,a2,,ana_1,a_2,\ldots,a_n, and the teams they belong to are t1,t2,,tnt_1,t_2,\ldots,t_n. Little QQ defines the excitement of the contest as:

$$D=\mathop{\min}_{1 \le i < j \le n} \begin{cases} |a_i - a_j| & t_i = t_j \\ +\infty & t_i \neq t_j \end{cases}$$

Now, nn possible contestants are given in nondecreasing order of skill. Since a contestant's skill is not fixed, the ii-th contestant is described by an interval [li,ri][l_i,r_i], meaning their actual skill in a contest can be any real number in this interval. Also, because the contestants' skills are monotonic nondecreasing by index, it is guaranteed that for all 1i<jn\forall 1 \le i < j \le n, we have lilj,rirjl_i \leq l_j, r_i \leq r_j.

Little QQ has qq contest plans. In the ii-th plan, contestants with indices between LiL_i and RiR_i will be invited. You need to help Little QQ determine whether there exists a way to assign teams such that the contest excitement may be at least DiD_i.

Input Format

This problem contains multiple test cases. The first line contains an integer TT (1T1051 \le T \le 10^5), indicating the number of test cases.

Then the test cases follow. For each test case:

The first line contains two integers nn and kk (1n5×1051 \le n \le 5 \times 10^5, 1kmin(5,n)1 \le k \le \min(5, n)), representing the number of possible contestants and the number of teams.

The next nn lines each contain two integers lil_i and rir_i (0liri10120 \le l_i \le r_i \le 10^{12}), describing the possible skill range of the ii-th contestant.

It is guaranteed that for all 1i<n\forall 1 \le i < n, lili+1l_i \le l_{i+1} and riri+1r_i \le r_{i+1}.

The next line contains an integer qq (1q1051 \le q \le 10^5), indicating the number of contest plans.

The next qq lines each contain three integers LiL_i, RiR_i, and DiD_i (1LiRin1 \le L_i \le R_i \le n, k(RiLi+1)k \mid (R_i - L_i + 1), 0Di10120 \le D_i \le 10^{12}), meaning that in the ii-th plan, contestants with indices from LiL_i to RiR_i will be invited, and Little QQ expects the excitement to be DiD_i.

It is guaranteed that n\sum n over all test cases does not exceed 10610^6, and q\sum q does not exceed 10510^5.

Output Format

For each test case, output qq lines. For the ii-th line, output YES or NO, indicating whether Little QQ's expected value for the ii-th plan may be achievable. You may output the answer in any letter case (uppercase or lowercase). For example, yEs, yes, Yes, and YES are all considered affirmative answers.

2
4 2
1 1
3 3
4 4
6 6
3
1 2 3
3 4 2
1 4 2
5 1
1 3
2 3
4 6
7 10
8 12
6
1 3 2
1 3 3
2 4 4
2 4 5
3 5 4
3 5 5
YES
YES
YES
YES
NO
YES
NO
YES
NO

Hint

Translated by ChatGPT 5