#P3641. [APIO2016] 最大差分
[APIO2016] 最大差分
Description
There are strictly increasing nonnegative integers with . You need to find the maximum value among for .
Your program cannot read this integer sequence directly, but you can query information about the sequence through the provided function. Please refer to the implementation details below for your language.
You must implement a function that returns the maximum value of for .
Judging method The following judging method applies. If this differs from the main statement, this section prevails.
- Your code must not include the gap.h library.
- You must declare the functions findGap and MinMax as follows:
extern "C" void MinMax(long long,long long,long long*,long long*);
extern "C" long long findGap(int,int);
- spj and interaction library
- If you encounter issues, please contact the problem provider.
Implementation details
This problem only supports C++ (including cpp11, cpp14, cpp17).
You must implement a function findGap(T, N), which takes the following parameters and returns a value of type long long:
- : subtask ID ( or ).
- : the length of the sequence.
Your function findGap may call the system-provided query function MinMax(s, t, &mn, &mx). The first two parameters and are of type long long, and the last two parameters &mn and &mx are pointers to long long (mn and mx are long long variables). When MinMax(s, t, &mn, &mx) returns, mn will store the minimum such that , and mx will store the maximum such that . If there is no number from the sequence in the interval , both mn and mx will be set to . You must ensure when querying; otherwise, the program will terminate and the test will receive a score of .
Sample 1
C/C++
Consider .
The answer should be , which can be obtained using the following queries to MinMax:
- Call MinMax(1, 2, &mn, &mx), then both mn and mx return .
- Call MinMax(3, 7, &mn, &mx), then mn returns , and mx returns .
- Call MinMax(8, 9, &mn, &mx), then both mn and mx return .
Sample judging method
The sample judge reads two lines from standard input. The first line contains two integers, the subtask ID and the sequence length . The second line contains strictly increasing nonnegative integers. Then the program writes two lines to standard output: the first line is the return value of findGap, and the second line is the value of the cost .
The following input describes the sample above:
2 4
2 3 6 8
Note that the actual interaction library and spj encrypt the testdata.
Constraints and agreements
For all test cases, .
Before each test case starts, will be initialized to .
Subtask 1 (30 points): Each call to MinMax increases by . To receive full points, you must ensure for all test cases in this subtask.
Subtask 2 (70 points): Let be the number of sequence elements within the interval for a MinMax call. Each call to MinMax increases by . For each test case, if , you will receive 70 points; otherwise, you will receive points. Your score for this subtask is the minimum over all its test cases.
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号