#P3634. Identifying Hidden Ninjas
Identifying Hidden Ninjas
Identifying Hidden Ninjas
APIO Kingdom is under attack by ninjas! These ninjas are very powerful because they can hide in the shadows making them invisible to others. The entire kingdom except the APIO Castle is occupied. In front of the castle there are bushes numbered from to . Exactly ninjas are hiding behind exactly bushes. Inside the castle, there are guards. Guard monitors a contiguous range of bushes from to . Each guard reports whether or not there is at least one ninja in his range. In particular, if the report is 1 then there is at least one ninja in the range, and if the report is 0 then there is no ninja among those bushes. Under the constraint that the positions of ninjas (i.e. the set with ) must be consistent with every guard's report, your task is to determine all bushes that definitely hide a ninja, i.e. bushes such that in every ninja arrangement consistent with the guard reports, bush contains a ninja.
More formally, let be 1 if bush hides a ninja and 0 otherwise. You are given that [ \sum_{i=1}^{N}x_i=K,] and for each guard with report monitoring bushes from to , it holds that [ \text{if } r=1, ; \sum_{i=A}^{B} x_i \ge 1 \quad \text{and} \quad \text{if } r=0, ; \sum_{i=A}^{B} x_i = 0.] A bush is guaranteed to have a ninja if in every solution (assignment) satisfying these conditions, we have .
Your program should output all such bush numbers in increasing order (separated by spaces).
inputFormat
The first line contains three integers , , and . Each of the following lines contains three integers , , and , where and () denote the range that guard monitors and is either 0 or 1 representing the guard’s report.
outputFormat
Output the bush numbers that are guaranteed to hide a ninja in increasing order, separated by a space. If no bush is guaranteed, output an empty line.
sample
5 2 3
1 3 1
2 5 1
3 4 0
</p>