#P15061. 琥峪枫
琥峪枫
Background
Do not use .
You need to add the following content at the top of your file, and submit using C++17 or a higher language standard:
long long ask(int u, int d);
Problem Description
This is an interactive problem.
Given a positive integer . Let .
The interactive library hides a permutation of and a sequence of length , where each element is a positive integer not greater than .
Now there is a full binary tree of depth with nodes, and the root is node . Also, for any node satisfying , its parent node is .
In each query, you can choose two integers satisfying and . The interactive library will return the sum of over all nodes such that . In particular, if there is no such node , the interactive library will return .
Here, is the number of edges on the simple path between node and node . In particular, .
You need to determine using no more than queries. The contestant’s score depends on the number of queries for a single testdata and, for any integer , the maximum number of times you query the integer .
It is not guaranteed that the permutation and the sequence are fixed, i.e., the interactive library may be adaptive.
Implementation Details
You need to implement the following function:
long long solve(int subtask, int h);
subtaskindicates the test point index;- is the height of the binary tree;
- This function should return the value of ;
- For each test point, this function may be called multiple times by the interactive library.
You can send a query to the interactive library by calling:
long long ask(int u, int d);
- is the center node of the query, and you must ensure ;
- is the distance limit, and you must ensure ;
- This function will return the sum of values of nodes whose distance to node is exactly .
The problem guarantees that within the allowed operation limit, the interactive library will run in no more than second; the memory usage of the interactive library is fixed and does not exceed .
Interaction Example
Suppose , , the hidden permutation is , and the node weights are . The following is a valid interaction:
| Contestant Program | Interactive Library | Explanation |
|---|---|---|
Call tree(1, 2) |
Start testing | |
Call ask(1, 1) |
Return | The only node at distance from is node , sum is |
Call ask(2, 1) |
Return | Nodes at distance from are nodes , sum is |
Call ask(3, 1) |
Return | The only node at distance from is node , sum is |
| End and return | Print the interaction result | Interaction ends, correct result |
Hint
Constraints
For all testdata, it is guaranteed that: , number of test cases , and across all data the sum of satisfies .
This problem has test points. The score and constraints for each test point are shown below.
| Test Point Index | Score | Special Property |
|---|---|---|
| Guaranteed , | ||
| No special restrictions |
Scoring
This problem will first be subject to the same restrictions as usual, e.g., a compilation error will cause the whole problem to score points; runtime errors, time limit exceeded, and memory limit exceeded will cause the corresponding test point to score points. Contestants can only access variables or data defined by themselves and those provided by the interactive library, and the corresponding memory space. Attempts to access other memory locations may cause compilation errors or runtime errors.
In each call to solve, the number of operations used by the program, , must satisfy , otherwise it will receive points.
Based on the above conditions:
-
In test point , the program gets full marks if and only if the return value of
solveis correct. -
In test point , the score is computed as follows:
- If the return value of
solveis incorrect, the score is . - If all return values of
solveare correct, then each testdata in this test point is scored separately: let be the number of operations used, and for any integer , let be the maximum number of times the integer is queried. Then the program gets points, where is the maximum score among all satisfied conditions in the table below:
Condition Score Here, is computed as follows:
- If the return value of
Translated by ChatGPT 5