IOI '20 P1 - Comparing Plants
View as PDFHazel the botanist visited a special exhibition in the Singapore Botanical Gardens. In this exhibition,  plants of distinct heights are placed in a circle. These plants are labelled from 
 to 
 in clockwise order, with plant 
 beside plant 
.
For each plant  
, Hazel compared plant 
 to each of the next 
 plants in clockwise order, and wrote down the number 
 denoting how many of these plants 
 are taller than plant 
. Thus, each value 
 depends on the relative heights of some 
 consecutive plants.
For example, suppose , 
 and 
. The next 
 plants in clockwise order from plant 
 would be plant 
 and plant 
. If plant 
 was taller than plant 
 and plant 
 was shorter than plant 
, Hazel would write down 
.
You may assume that Hazel recorded the values  correctly. Thus, there is at least one configuration of distinct heights of plants consistent with these values.
You were asked to compare the heights of  pairs of plants. Sadly, you do not have access to the exhibition. Your only source of information is Hazel's notebook with the value 
 and the sequence of values 
.
For each pair of different plants  and 
 that need to be compared, determine which of the three following situations occurs:
- Plant 
is definitely taller than plant
: in any configuration of distinct heights
consistent with the array
we have
.
 - Plant 
is definitely shorter than plant
: in any configuration of distinct heights
consistent with the array
we have
.
 - The comparison is inconclusive: neither of the previous two cases applies.
 
Implementation details
You should implement the following procedure:
void init(int k, std::vector<int> r)
: the number of consecutive plants whose heights determine each individual value
.
: an array of size
, where
is the number of plants taller than plant
among the next
plants in clockwise order.
- This procedure is called exactly once, before any calls to 
compare_plants. 
int compare_plants(int x, int y)
: labels of the plants to be compared.
- This procedure should return:
if plant
is definitely taller than plant
,
if plant
is definitely shorter than plant
,
if the comparison is inconclusive.
 - This procedure is called exactly 
times.
 
Examples
Example 1
Consider the following call:
init(3, {0, 1, 1, 2})
Let's say the grader calls compare_plants(0, 2). Since  we can immediately infer that plant 
 is not taller than plant 
. Therefore, the call should return 
.
Let's say the grader calls compare_plants(1, 2) next. For all possible configurations of heights that fit the constraints above, plant  is shorter than plant 
. Therefore, the call should return 
.
Example 2
Consider the following call:
init(2, {0, 1, 0, 1})
Let's say the grader calls compare_plants(0, 3). Since , we know that plant 
 is taller than plant 
. Therefore, the call should return 
.
Let's say the grader calls compare_plants(1, 3) next. Two configurations of heights  and 
 are both consistent with Hazel's measurements. Since plant 
 is shorter than plant 
 in one configuration and taller than plant 
 in the other, this call should return 
.
Constraints
for all
- There exists one or more configurations of distinct heights of plants consistent with the array 
.
 
Subtasks
- (
points)
 - (
points)
 - (
points)
 - (
points) The correct answer to each call of
compare_plantsisor
.
 - (
points)
 - (
points)
for each call of
compare_plants. - (
points) No additional constraints.
 
Sample grader
The sample grader reads the input in the following format:
- line 
:
 - line 
:
 - line 
:
for the
-th call to
compare_plants 
The sample grader prints your answer in the following format:
- line 
: return value of the
-th call to
compare_plants. 
Comments