Codeforces Global Round 28
F
Kevin and Math Class
Codeforces
2500
原题
← EG →
翻译中…

Kevin is a student from Eversleeping Town, currently attending a math class where the teacher is giving him division exercises.

翻译中…

On the board, there are two rows of positive integers written, each containing $ n $ numbers. The first row is $ a_1, a_2, \ldots, a_n $, and the second row is $ b_1, b_2, \ldots, b_n $.

翻译中…

For each division exercise, Kevin can choose any segment $ [l, r] $ and find the smallest value $ x $ among $ b_l, b_{l+1}, \ldots, b_r $. He will then modify each $ a_i $ for $ l \leq i \leq r $ to be the ceiling of $ a_i $ divided by $ x $.

翻译中…

Formally, he selects two integers $ 1 \leq l \leq r \leq n $, sets $ x = \min_{l \leq i \leq r} b_i $, and changes all $ a_i $ for $ l \leq i \leq r $ to $ \lceil \frac{a_i}{x} \rceil $.

翻译中…

Kevin can leave class and go home when all $ a_i $ become $ 1 $. He is eager to leave and wants to know the minimum number of division exercises required to achieve this.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ($ 1 \le t \le 10^4 $).

翻译中…

The first line of each test case contains an integer $ n $ ($ 1 \le n \leq 2 \cdot 10^5 $) — the length of the sequence $ a $ and $ b $.

翻译中…

The second line of each test case contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ($ 1 \le a_i \le 10^{18} $) — the first row of integers on the board.

翻译中…

The third line of each test case contains $ n $ integers $ b_1, b_2, \ldots, b_n $ ($ 2 \le b_i \le 10^{18} $) — the second row of integers on the board.

翻译中…

It is guaranteed that the sum of $ n $ over all test cases doesn't exceed $ 2 \cdot 10^5 $.

翻译中…

Output

翻译中…

For each test case, output one integer — the minimum number of division exercises required to leave class.

翻译中…

Note

翻译中…

For the first test case: $ [{\color{red}{5,4}},2]\xrightarrow[\min(b_1,b_2)=3]{\text{operate segment }[1,2]}[{\color{red}{2,2,2}}]\xrightarrow[\min(b_1,b_2,b_3)=2]{\text{operate segment }[1,3]}[1,1,1] $.

翻译中…

For the second test case: $ [{\color{red}{3,6,1}},3,2]\xrightarrow[\min(b_1,b_2,b_3)=3]{\text{operate segment }[1,3]}[1,{\color{red}{2,1,3}},2]\xrightarrow[\min(b_2,b_3,b_4)=2]{\text{operate segment }[2,4]}[1,1,1,{\color{red}{2,2}}]\xrightarrow[\min(b_4,b_5)=2]{\text{operate segment }[4,5]}[1,1,1,1,1] $.

翻译中…

样例

Input #1
3
3
5 4 2
6 3 2
5
3 6 1 3 2
3 5 3 2 2
6
8 3 3 7 5 8
3 2 3 4 2 3
Output #1
2
3
3
InputCopy OutputCopy
题目信息
题号
2048F
时间限制
2 s
内存限制
1024 MB
标签
暴力
数据结构
分治
动态规划
模拟
数学
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。