Problem J. Rikka with Time Complexity

时间限制 1000 ms   内存限制 512 MB

Calculating and comparing time complexity for algorithms are the most important necessary skills for CS students.

This semester, Rikka applies for the assistant of course "Algorithm Analysis". Now Rikka needs to set problems for the final examination, and she is going to set some tasks about time complexity.

Let $f_a(n) = \log \dots \log n$ (there are exactly $a$ $\log$ in this function, and $\log$ uses base $2$). And then, for an integer array $A$, Rikka defines $g_A(n)$ in the following way ($B$ is the suffix of $A$ with length $|A| - 1$):
\begin{align*}
g_A(n) = \begin{cases}
f_{A_1}(n) & |A| = 1 \\
f_{A_1}(n)^{g_B(n)} & |A| > 1
\end{cases}
\end{align*}

For example, $g_{[1,2]}(n) = (\log n) ^{\log \log n}$ and $g_{[3,1,1]}(n) = (\log \log \log n) ^{(\log n) ^{\log n}}$.

Now, given integer arrays $A$ and $B$, Rikka wants you to compare $g_A(n)$ with $g_B(n)$. i.e., let $k$ be $\lim_{n \rightarrow +\infty}\frac{g_A(n)}{g_B(n)}$. If $k = 0$, output $-1$; if $k = +\infty $, output $1$; otherwise output $0$.
 

输入数据

The first line contains a single number $t(1 \leq t \leq 10^5)$, the number of testcases.

For each testcase, the first line contains two integers $a,b(1 \leq a,b \leq 3)$, the length of $A$ and $B$.

The second line contains $a$ integers $A_i$ and the third line contains $b$ integers $B_i(1 \leq A_i,B_i \leq 10^9)$, which describe $A$ and $B$.
 

输出数据

For each testcase, output a single line with a single integer, the answer.
 

样例输入

复制
3
1 1
1
2
2 2
1 2
2 1
1 3
1
1000000000 3 3

样例输出

复制
1
-1
-1

提交

请先 登录

© 2025 FAQs Contact About