QOJ.ac

QOJ

时间限制: 7.5 s 内存限制: 512 MB 总分: 100

#4489. 乘2除2

统计

说明

本题与 Hack of Multiply 2 Divide 2 之间没有依赖关系。

Frank_DD 有一个长度为 $n$ 的序列 $a$。 每次操作,他可以选择一个数 $a_i$ ($1 \le i \le n$) 并将其变为 $a_i \cdot 2$ 或 $\lfloor \frac{a_i}{2} \rfloor$。 Frank_DD 想知道将序列 $a$ 变为非递减序列所需的最少操作次数。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 5$),表示测试用例的数量。接下来是 $T$ 个测试用例。 每个测试用例中: 第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示序列 $a$ 的长度。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^5$),表示序列 $a$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示将序列 $a$ 变为非递减序列所需的最少操作次数。

样例

输入格式 1

2
7
6 3 3 4 10 8 2
10
9 9 4 7 3 10 10 8 4 3

输出格式 1

4
11

说明

在第一个测试用例中,我们可以使用至少 4 次操作将序列 $a$ 变为非递减序列: $a_1 = \lfloor \frac{a_1}{2} \rfloor$ $a_5 = \lfloor \frac{a_5}{2} \rfloor$ $a_7 = a_7 \cdot 2$ $a_7 = a_7 \cdot 2$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.