#P8492. [IOI 2022] 无线电信号塔
[IOI 2022] 无线电信号塔
Background
Due to technical limitations, please do not use C++ 14 (GCC 9) to submit this problem.
This is an interactive problem. You only need to implement the functions required in the code.
Your code does not need to include any additional header files, and you do not need to implement the main function.
Problem Description
There are radio signal towers in Jakarta. These towers are arranged in a straight line and are numbered from to from left to right.
For each satisfying , tower has height meters.
All tower heights are distinct.
For a positive signal interference parameter , a pair of towers and () can communicate with each other if and only if there exists an intermediate tower such that:
- Tower is to the left of tower , and tower is to the right of tower , i.e., ;
- The heights of towers and are both at most meters.
Pak Dengklek wants to rent some towers to build his new radio network.
Your task is to answer queries from Pak Dengklek. Each query is as follows:
Given , , and ( and ), determine the maximum number of towers Pak Dengklek can rent, subject to all of the following conditions:
- Pak Dengklek can only rent towers with indices between and (inclusive);
- The signal interference parameter equals ;
- Every pair of rented towers must be able to communicate with each other.
Note that regardless of whether the intermediate tower is rented, two rented towers can still use tower to communicate.
Input Format
You need to implement the following functions:
void init(int N, int[] H)
- : the number of towers.
- : an array of length giving the heights of the towers.
- This function is called exactly once, and before any calls to
max_towers.
int max_towers(int L, int R, int D)
- , : the boundaries of the tower index range.
- : the value of the signal interference parameter .
- This function should return the maximum number of towers Pak Dengklek can rent (to build the radio network), where Pak Dengklek can only rent towers between and (inclusive), and the signal interference parameter equals .
- This function will be called exactly times.
Output Format
Consider the following sequence of function calls:
init(7, [10, 20, 60, 40, 50, 30, 70])
max_towers(1, 5, 10)
Pak Dengklek can rent towers , , and .
The diagram below illustrates this example, where the gray trapezoids represent the rented towers.

Towers and can communicate using tower , because and .
Towers and can communicate using tower .
Towers and can communicate using tower .
It is impossible to rent more than towers, so the function should return .
max_towers(2, 2, 100)
There is only tower in this range, so Pak Dengklek can only rent tower.
Therefore, the function should return .
max_towers(0, 6, 17)
Pak Dengklek can rent towers and .
Towers and can communicate using tower , because and .
It is impossible to rent more than towers, so the function should return .
Hint
Constraints
- (for all satisfying )
- (for all and satisfying )
Subtasks
- (4 points) There exists a tower () satisfying all of the following:
- For each with :
- For each with :
- (11 points) ,
- (12 points)
- (14 points)
- (17 points) ,
- (19 points) The value of is the same in all calls to
max_towers - (23 points) No additional constraints
Sample grader
The sample grader reads input in the following format:
- Line :
- Line :
- Line (): (corresponding to the -th query)
The sample grader prints your answers in the following format:
- Line (): the return value of
max_towersfor the -th query
Notes
In the statement, the function interfaces use general type names void, int, int64, int[] (array), and int[][] (array of arrays).
In C++, the grader will use appropriate data types or implementations, as shown in the tables below:
void |
int |
int64 |
int[] |
|---|---|---|---|
void |
int |
long long |
std::vector<int> |
int[][] |
The length of array a |
|---|---|
std::vector<std::vector<int>> |
a.size() |
Translated by ChatGPT 5