#P15845. [Bulgarian NOI 2024] GCD5.0
[Bulgarian NOI 2024] GCD5.0
Background
When submitting this problem on Luogu, please choose the language standard >= C++17. You do not need to include #include "gcd5.h". Instead, put
long long query(int x);
void answer(long long a, long long b);
void solve(int n);
at the beginning of your program.
Problem Description
This problem has nothing to do with GCD :)
Niki has already chosen hidden lines (or linear functions), and you need to find them. Formally, the -th line is defined by a pair of coefficients , and represents the linear function .
Niki does not like fractions, so all coefficients are integers.
To find these hidden lines, you can ask queries of the form: “at a given integer , which line attains the maximum value”. As you already know, Niki hates decimals, so you can only ask this for integer values . Formally, the answer to such a query is .
It is guaranteed that a solution exists. Besides the conditions above, it is also guaranteed that each line becomes the maximum for at least integer values within the interval ; in other words, for every line , there exist at least 3 values such that for all , . In addition, no two lines have the same slope .
Write a program that finds all hidden lines using as few queries as possible.
Interaction Format
This is an interactive problem. You only need to implement a solve function of the following type:
void solve(int n);
This function will be called exactly once, with the parameter equal to the number of lines. Your implementation may use the following two helper functions:
long long query(int x);
void answer(long long a, long long b);
By calling query(x), you can obtain the maximum function value among all lines at the given . The score you get for each test depends on how many times you call this function. You may only call this function for .
The answer function must be called exactly times—once for each line you find. The order of calls does not matter.
Your code must not include a main function, but it may include other helper functions, classes, variables, etc. Your code must include the header file gcd5.h.
#include "gcd5.h"
For convenient local testing, we provide a local grader Lgrader.cpp and a copy of the header file gcd5.h. You need to compile your code together with the local grader for testing. You can put them in the same folder and use the following command:
g++ -O2 -std=c++17 -Wl,--stack,1073741824 -Wall gcd5.cpp Lgrader.cpp -o gcd5.exe
Hint
Example
Let , and the hidden lines are and . One possible interaction process is as follows:
| Contestant | Grader |
|---|---|
solve(2) |
|
query(1) |
4 |
query(5) |
0 |
query(6) |
1 |
answer(-1, 5) |
|
answer(1, -5) |
Subtasks
| Subtask | Score | |
|---|---|---|
The score of a subtask equals the minimum score among all its subtest points.
Scoring
For each test point, you will receive a result computed as follows:
- If you make an invalid query, or fail to correctly identify all hidden lines, the score is 0.
- Let be the total number of queries you made.
- If , the score is 0.
- Otherwise, the score for that test point is:
Constraints
- .
- , and each is an integer.
- , and each is an integer.
Translated by ChatGPT 5