#P6829. [IOI 2020] 植物比较
[IOI 2020] 植物比较
Description
Botanist Hazel visited a special exhibition at the Singapore Botanic Gardens. In this exhibition, there are plants with pairwise distinct heights, arranged in a circle. The plants are numbered clockwise from to , and plant is adjacent to plant .
For each plant , Hazel compares it with the next plants in the clockwise direction, and records a value , which indicates how many of those plants are taller than plant . Therefore, each value is determined by the relative heights within some consecutive block of plants.
For example, suppose , , and . The next plants clockwise from plant are plants and . If plant is taller than plant , and plant is shorter than plant , then Hazel records .
You may assume that all the values recorded by Hazel are correct. That is, there exists at least one set of pairwise distinct heights that matches Hazel’s recorded values.
In this problem, you need to compare the heights of pairs of plants. Since you did not get to visit the exhibition, the only information you have is Hazel’s notebook, which contains and the sequence .
For each pair of plants and to be compared (with ), determine which of the following cases applies:
- Plant is definitely taller than plant : for any set of pairwise distinct heights that matches array , we have .
- Plant is definitely shorter than plant : for any set of pairwise distinct heights that matches array , we have .
- The comparison is inconclusive: neither of the above two cases holds.
Implementation Details
You are required to implement the following functions:
void init(int k, std::vector<int> r)
- : the number of consecutive plants that determine each value .
- : an array of size , where is the number of plants among the next plants clockwise from plant that are taller than it.
- This function is called exactly once, before any call to
compare_plants.
int compare_plants(int x, int y)
- : the indices of the plants to be compared.
- This function should return:
- , if plant is definitely taller than plant ,
- , if plant is definitely shorter than plant ,
- , if the comparison is inconclusive.
- This function is called exactly times.
Hint
Sample Explanation
Example 1
Consider the following call:
init(3, [0, 1, 1, 2])
Suppose the grader calls compare_plants(0, 2). From , we can conclude that plant is not taller than plant , so this call should return .
Suppose the grader then calls compare_plants(1, 2). Since for every set of plant heights satisfying the above conditions, plant is shorter than plant , this call should return .
Example 2
Consider the following call:
init(2, [0, 1, 0, 1])
Suppose the grader calls compare_plants(0, 3). From , we can conclude that plant is taller than plant , so this call should return .
Suppose the grader then calls compare_plants(1, 3). Two height assignments and both match Hazel’s observations. Since in the first case plant is shorter than plant , while in the second case it is taller than plant , this call should return .
Constraints
- .
- .
- (for all ).
- .
- There exists one or more sets of pairwise distinct heights that match the array .
Subtasks
- (5 points) .
- (14 points) .
- (13 points) .
- (17 points) The correct answer to each
compare_plantscall is or . - (11 points) .
- (15 points) In each
compare_plantscall, . - (25 points) No additional constraints.
Example Grader
The example grader reads the input in the following format:
Line :
Line :
Line : , representing the parameters of the -th call to compare_plants
The example grader prints your answers in the following format:
Line : the return value of the -th call to compare_plants
Translated by ChatGPT 5
京公网安备 11011102002149号