#P12541. [APIO2025] Hack!

    ID: 14105 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2025APIO交互题Special Judge构造大步小步算法 BSGS

[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 nn buckets, which are numbered from 00 to n1n-1. Unfortunately, you do not know the value of nn and wish to recover it.

When you insert an integer xx into the hash table, it is inserted to the (xmodn)(x \bmod n)-th bucket. If there are bb elements in this bucket prior to the insertion, this will cause bb hash collisions to occur.

By giving kk distinct integers x[0],x[1],,x[k1]x[0], x[1], \dots, x[k-1] 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 kk integers in one query will incur a cost of kk.

For example, if n=5n = 5, feeding the interactor with x=[2,15,7,27,8,30]x = [2, 15, 7, 27, 8, 30] would cause 4 collisions in total:

Operation New collisions Buckets
initially - [],[],[],[],[][], [], [], [], []
insert x[0]=2x[0] = 2 00 [],[],[2],[],[][], [], [2], [], []
insert x[1]=15x[1] = 15 [15],[],[2],[],[][15], [], [2], [], []
insert x[2]=7x[2] = 7 11 [15],[],[2,7],[],[][15], [], [2, 7], [], []
insert x[3]=27x[3] = 27 22 [15],[],[2,7,27],[],[][15], [], [2, 7, 27], [], []
insert x[4]=8x[4] = 8 00 [15],[],[2,7,27],[8],[][15], [], [2, 7, 27], [8], []
insert x[5]=30x[5] = 30 11 [15,30],[],[2,7,27],[8],[][15, 30], [], [2, 7, 27], [8], []

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 nn using a total cost of at most 10000001\,000\,000.

Implementation details

You should implement the following procedure:

int hack()
  • This procedure should return an integer – the hidden value of nn.
  • 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)
  • xx: an array of distinct numbers, where 1x[i]10181 \leq x[i] \leq 10^{18} for each ii.
  • This function returns the number of collisions created by inserting the elements of xx to an unordered_set.
  • This procedure can be called multiple times. The sum of length of xx over all calls within one call to hack() must not exceed 10000001\,000\,000.

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 10000001\,000\,000 applies to each test case. In general, if there are tt calls to hack(), you may use a total cost of no more than t×1000000t \times 1\,000\,000, with each individual call to hack() using a cost no more than 10000001\,000\,000.

The interactor is not adaptive, i.e. the values of nn 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]) 44
collisions([1, 2, 3]) 00
collisions([10, 20, 30, 40, 50]) 1010

After that, if you find that the value of nn is 55, the procedure hack() should return 55.

Then grader will make another call:

hack()

Let's say, within the function, you make following calls:

Call Returned value
collisions([1, 3]) 11
collisions([2, 4])

The only nn which satisfies the queries is 22. So, the procedure hack() should return 22.

Constraints

  • 1t101 \leq t \leq 10, where tt is the number of multitests.
  • 2n1092 \leq n \leq 10^9
  • 1x[i]10181 \leq x[i] \leq 10^{18} for each call to collisions().

Subtasks

  1. (8 points) n500000n \leq 500\,000
  2. (17 points) n1000000n \leq 1\,000\,000
  3. (75 points) No additional constraints.

In the last subtask, you can get partial score. Let qq 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
1000000<q1\,000\,000 < q 00
110000<q1000000110\,000 < q \leq 1\,000\,000 $75 \cdot \log_{50} \left( \frac{10^6}{q - 90000} \right)$
q110000q \leq 110\,000 7575

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 00.

Sample Grader

The sample grader reads the input in the following format:

  • line 1: tt

Then, tt lines follow, each containing a value of nn:

  • line 1: nn

For each test case, let mm be the return value of hack(), and cc be the total cost of all queries. The sample grader prints your answer in the following format:

  • line 1: mcm \, c