距离一无所有还要多久?AI (CI翻译)
Before her final sortie, Chtholly asks Willem three questions.
在她最后一次出击前,Chtholly 向 Willem 提出了三个问题。AI (CI翻译)
The first is this: if the end is inevitable, how long will it take until nothing remains?
第一个问题是:如果终结不可避免,那么要过多久才会一无所有?AI (CI翻译)
Willem cannot answer her directly. Instead, he writes down $n$ positive integers $a_1,a_2,\ldots,a_n$.
Willem 无法直接回答她。于是,他写下了 $n$ 个正整数 $a_1,a_2,\ldots,a_n$。AI (CI翻译)
Each operation takes one second. In one operation, Willem does the following:
每次操作耗时一秒。在一次操作中,Willem 会执行以下步骤:AI (CI翻译)
- Choose an index
$p$($1\le p\le n$); - Then, replace
$a_p$with$\left\lfloor\dfrac{a_p}{2}\right\rfloor$, and for every$i\ne p$, replace$a_i$by$\left\lceil\dfrac{a_i}{2}\right\rceil$. All replacements are performed simultaneously.
- 选择一个下标
$p$($1\le p\le n$); - 将
$a_p$替换为$\left\lfloor\dfrac{a_p}{2}\right\rfloor$,并对每个$i\ne p$,将$a_i$替换为$\left\lceil\dfrac{a_i}{2}\right\rceil$。所有替换同时进行。
Find the minimum number of seconds needed to make all $n$ integers equal to $0$.
求使全部 $n$ 个整数都变为 $0$ 所需的最少秒数。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来描述各个测试用例。AI (CI翻译)
The first line of each test case contains one integer $n$ ($1\le n\le2\cdot10^5$) — the number of integers.
每个测试用例的第一行包含一个整数 $n$($1\le n\le2\cdot10^5$)——整数的数量。AI (CI翻译)
The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1\le a_i\le10^9$) — the initial integers.
每个测试用例的第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$($1\le a_i\le10^9$)——初始整数。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$.
保证所有测试用例的 $n$ 之和不超过 $2\cdot10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output a single integer — the minimum number of seconds needed to make all integers equal to $0$.
对于每个测试用例,输出一个整数——使所有整数都变为 $0$ 所需的最少秒数。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, the only integer changes as $3\to1\to0$, so the answer is $2$.
在第一个测试用例中,唯一的整数按 $3\to1\to0$ 变化,因此答案为 $2$。AI (CI翻译)
In the second test case, an integer equal to $1$ becomes $0$ only when its index is chosen. Thus, at least $3$ seconds are necessary, and choosing every index once is sufficient.
在第二个测试用例中,等于 $1$ 的整数只有在其下标被选中时才会变为 $0$。因此,至少需要 $3$ 秒,而将每个下标各选择一次即可满足要求。AI (CI翻译)
In the third test case, an optimal sequence is:
在第三个测试用例中,一种最优操作序列如下:AI (CI翻译)
- Choose
$p=1$:$[1,2,4]\to[0,1,2]$; - Choose
$p=2$:$[0,1,2]\to[0,0,1]$; - Choose
$p=3$:$[0,0,1]\to[0,0,0]$.
- 选择
$p=1$:$[1,2,4]\to[0,1,2]$; - 选择
$p=2$:$[0,1,2]\to[0,0,1]$; - 选择
$p=3$:$[0,0,1]\to[0,0,0]$。
In the fourth test case, an optimal sequence is $[5,2]\to[2,1]\to[1,0]\to[0,0]$, where the chosen indices are $1$, $2$, and $1$.
在第四个测试用例中,一种最优操作序列为 $[5,2]\to[2,1]\to[1,0]\to[0,0]$,其中选择的下标依次为 $1$、$2$、$1$。AI (CI翻译)
样例
5
1
3
3
1 1 1
3
1 2 4
2
5 2
6
1 2 3 4 5 6
2
3
3
3
6
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。