#P12541. [APIO2025] Hack!
[APIO2025] Hack!
题目描述
It has been an hour into a Codeforces contest, when you notice that another contestant in your room has solved a problem using an unordered_set
. Time to hack!
You know that unordered_set
uses a hash table with buckets, which are numbered from to . Unfortunately, you do not know the value of and wish to recover it.
When you insert an integer into the hash table, it is inserted to the -th bucket. If there are elements in this bucket prior to the insertion, this will cause hash collisions to occur.
By giving distinct integers to the interactor, you can find out the total number of hash collisions that had occurred while creating an unordered_set
containing the numbers. However, feeding this interactor integers in one query will incur a cost of .
For example, if , feeding the interactor with would cause 4 collisions in total:
Operation | New collisions | Buckets |
---|---|---|
initially | ||
insert | ||
insert | ||
insert | ||
insert | ||
insert | ||
insert |
Note that the interactor creates the hash table by inserting the elements in order into an initially empty unordered_set
, and a new empty unordered_set
will be created for each query. In other words, all queries are independent.
Your task is to find the number of buckets using a total cost of at most .
Implementation details
You should implement the following procedure:
int hack()
- This procedure should return an integer – the hidden value of .
- For each test case, the grader may call this function more than once. Each call should be processed as a separately new scenario.
Within this procedure, you may call the following procedure:
long long collisions(std::vector<long long> x)
- : an array of distinct numbers, where for each .
- This function returns the number of collisions created by inserting the elements of to an
unordered_set
. - This procedure can be called multiple times. The sum of length of over all calls within one call to
hack()
must not exceed .
Note: Since the procedure hack()
will be called more than once, contestants need to pay attention to the impact of the remaining data of the previous call on the current call, especially the state stored in global variables.
The cost limit of applies to each test case. In general, if there are calls to hack()
, you may use a total cost of no more than , with each individual call to hack()
using a cost no more than .
The interactor is not adaptive, i.e. the values of are fixed before the start of interaction.
提示
Example
Suppose, there are 2 multitests. The grader will make a following call:
hack()
Let's say, within the function, you make following calls:
Call | Returned value |
---|---|
collisions([2, 15, 7, 27, 8, 30]) |
|
collisions([1, 2, 3]) |
|
collisions([10, 20, 30, 40, 50]) |
After that, if you find that the value of is , the procedure hack()
should return .
Then grader will make another call:
hack()
Let's say, within the function, you make following calls:
Call | Returned value |
---|---|
collisions([1, 3]) |
|
collisions([2, 4]) |
The only which satisfies the queries is . So, the procedure hack()
should return .
Constraints
- , where is the number of multitests.
- for each call to
collisions()
.
Subtasks
- (8 points)
- (17 points)
- (75 points) No additional constraints.
In the last subtask, you can get partial score. Let be the maximum total cost among all invocations of hack()
over every test case of the subtask. Your score for this subtask is calculated according to the following table:
Condition | Points |
---|---|
$75 \cdot \log_{50} \left( \frac{10^6}{q - 90000} \right)$ | |
If, in any of the test cases, the calls to the procedure collisions()
do not conform to the constraints described in Implementation Details, or the number returned by hack()
is incorrect, the score of your solution for that subtask will be .
Sample Grader
The sample grader reads the input in the following format:
- line 1:
Then, lines follow, each containing a value of :
- line 1:
For each test case, let be the return value of hack()
, and be the total cost of all queries. The sample grader prints your answer in the following format:
- line 1: