|
||||||||||
Rikka with Time ComplexityTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 759 Accepted Submission(s): 269 Problem Description 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$. Input 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$. Output For each testcase, output a single line with a single integer, the answer. Sample Input
Sample Output
Source | ||||||||||
|