#P3634. [APIO2012] 守卫

[APIO2012] 守卫

Description

In front of the castle, there are NN bushes, numbered from 11 to NN. There are KK ninjas hiding behind exactly KK bushes.

There are MM guards in the APIO castle. Guard ii watches a contiguous segment of bushes numbered from AiA_i to BiB_i. Each guard reports to the king whether there is a ninja within their monitored range.

As the king’s servant, you need to tell the king, based on the guards’ reports, which bushes must contain a ninja; that is, for any placement of ninjas that is consistent with the reports, there is a ninja behind that bush.

Output all such bush indices.

Input Format

The first line contains three space-separated integers N,K,MN, K, M. NN is the number of bushes, KK is the number of ninjas, and MM is the number of guards.

The next MM lines each describe one guard. The ii-th line contains three integers Ai,Bi,CiA_i, B_i, C_i, meaning that the ii-th guard monitors the range from AiA_i to BiB_i (with AiBiA_i \leq B_i). CiC_i is 00 or 11: 00 means no ninja is seen within the range; 11 means there is at least one ninja within the range.

The input guarantees that at least one placement of ninjas satisfies all constraints.

Output Format

If there exist bushes that must contain a ninja, output their indices in increasing order, one per line. If there are XX such bushes, output XX lines.

Otherwise, output a single line containing -1.

5 3 4 
1 2 1 
3 4 1 
4 4 0 
4 5 1
3
5

5 1 1 
1 5 1
-1

Hint

Sample Explanation 11

In this sample, there are two possible placements: 1,3,51, 3, 5 or 2,3,52, 3, 5. Therefore, 33 and 55 must contain a ninja. For bush 11, there exists a placement where it has a ninja and another where it does not, so 11 should not be output. Similarly, 22 should not be output.

Sample Explanation 22

In this sample, no bush is guaranteed to contain a ninja.

Constraints

1N1051 \leq N \leq 10^5; 1KN1 \leq K \leq N; 0M<1050 \leq M < 10^5.

For 10%10\% of the testdata, N20N \leq 20, M100M \leq 100.

For 50%50\% of the testdata, N1000N \leq 1000, M1000M \leq 1000.

Translated by ChatGPT 5