luogu#P5208. [WC2019] I 君的商店
[WC2019] I 君的商店
Background
Special Notice.
Some notes when submitting this problem on Luogu (if it differs from the original statement, please follow what is written here):
- Different from the original problem, you do not need, and should not, include the
shop.hheader file at the beginning of your program. - When submitting, please add the following function declaration in your program:
int query(int *S, int nS, int *T, int nT);
- Only
C++(includingC++,C++11,C++14,C++17) submissions are supported.
Problem Description
Mr. V, Mr. I, and Mr. Y are good friends.
Mr. I recently opened a shop. The shop has kinds of items (with IDs being integers from ). Each kind of item has an unlimited supply. The unit price of each item is either or .
Mr. V wants to know the price of every item. Through some supernatural power, he already knows that among these items, the number of items priced at is exactly odd/even, and there is at least one item whose price is .
However, Mr. V does not want to ask Mr. I himself. He chooses the following method: he prepares money for Mr. Y, and lets Mr. Y run errands for him. Each time, he specifies two non-empty item sets to Mr. Y (items within the same set must be pairwise distinct, i.e. each kind of item can appear at most once in each set). Mr. Y will go to the shop, buy the items in the two sets respectively, bring them back, and tell Mr. V which set has a larger total price. However, when the sums of the two sets are equal, Mr. Y will answer Mr. V according to Mr. I’s instructions.
Carrying many items is tiring, so we define the physical cost of one errand as , where denotes the number of items in set .
Your task is to write a program to help Mr. V decide how to make Mr. Y run errands in a reasonable way, so as to deduce the value of every kind of item. Mr. Y’s stamina is limited, so you cannot make him too tired, i.e. you cannot let his total physical cost exceed a preset threshold .
Implementation Details
You do not need, and should not, implement the main function. You only need to implement the following function:
find_price(task_id, N, K, ans)- Here
task_iddenotes the subtask ID (see Constraints and Rules). denotes the number of items, and the meaning of is:- If , it means there are an even number of items with value .
- If , it means there are an odd number of items with value .
- You need to store the computed item prices in the array , where is the price of the item with ID .
You can make queries to the interactive library by calling the following function:
query(S, nS, T, nT)- Here . Arrays and describe the two sets respectively. You must ensure:
- .
- $\forall 0 \le i < \text{nS} , 0 \le \text{S[i]} < N$.
- $\forall 0 \le i < \text{nT} , 0 \le \text{T[i]} < N$.
means “for any”. For example, $\forall 0 \le i < \text{nS} , 0 \le \text{S[i]} < N$ means: “for any in , is in ”.
- The time complexity of calling this function once is . It returns or , and the meaning is:
- If the sum of prices of items in set is larger, return .
- If the sum of prices of items in set is larger, return .
- Otherwise, return or according to some unknown rule.
- As stated, we define the cost of one call as .
During evaluation, the interactive library may call find_price multiple times (no more than times). Each call represents a new price-guessing game, and all item prices will be reset.
Input Format
The executable will read input from standard input in the following format:
The first line contains an integer , the number of test groups. For each group:
- The first line contains two integers .
- The next line contains a binary string of length , where denotes the price of item . You need to ensure that at least one item has price .
After reading is finished, the interactive library will call the find_price function times.
Then the interactive library will check whether your function is correct each time. If all are correct, it will output Correct; otherwise, it will output the corresponding error message.
Hint
Scoring Rules
This problem is first subject to the same limits as non-interactive programming problems. For example, a compilation error will cause the entire problem to score points; runtime error, exceeding the time limit, exceeding the memory limit, etc. will cause the corresponding test points to score points. You may only access variables you define yourself and the variables provided by the interactive library and their corresponding memory space. Attempting to access other memory may cause a compilation error or runtime error.
Under the above conditions, in a test point, you get full score if and only if, in every call to find_price:
- Every call to
queryfollows the rules, and the sum of call costs does not exceed . - Your function correctly computes the array .
In a test point, if you do not get full score, then you get points.
Subtasks
Let the upper bound of the total cost be , and denote the answer array as :
- Subtask 1: .
- Subtask 2: .
- Subtask 3: . It is guaranteed that , if then .
- Subtask 4: .
- Subtask 5: .
- Subtask 6: .
Note
Mr. I may not be willing to let Mr. V know the price of every item. When the sums are equal, he will answer in his own way.
Subtask Scores
In this contest, the score distribution of test points (or subtasks) depends on whether you are a CTT contestant. The score settings for this problem are as follows:
| Subtask ID | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| CTT Score | ||||||
| Non-CTT Score |
Luogu uses the CTT scoring scheme when judging.
Translated by ChatGPT 5