Comparing Plants
Time limit4sMemory limit1024 MB
Given k and the counts r[i] of taller plants among the next k-1 plants in a circle, decide for each query pair whether one plant is always taller than the other.
- Level
Hard10 of 10
- Topics
- Prefix sum, Segment tree, Graph
- Solved
- No attempts yet
Problem
Hazel the botanist visited a special exhibition in the Singapore Botanical Gardens. The exhibition has plants of distinct heights placed in a circle. The plants are labelled from to in clockwise order, with plant beside plant .
For each plant (), Hazel compared plant with each of the next plants in clockwise order and wrote down , the number of these plants that are taller than plant . Each therefore depends on the relative heights of consecutive plants.
For example, let , , and . The next plants clockwise from plant are plants and . If plant is taller than plant and plant is shorter than plant , Hazel writes .
You may assume Hazel recorded every correctly. At least one arrangement of distinct heights matches these values.
You need to compare the heights of pairs of plants. You cannot enter the exhibition. Your only information is the value and the sequence in Hazel's notebook.
For each pair of different plants and , decide which of the following holds:
- Plant is definitely taller than plant : in every arrangement of distinct heights consistent with , .
- Plant is definitely shorter than plant : in every consistent arrangement, .
- The comparison is inconclusive: neither of the above holds.
Constraints
(for all )
At least one arrangement of distinct heights is consistent with .