F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Rikka with Time Complexity

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 758    Accepted Submission(s): 268


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
3 1 1 1 2 2 2 1 2 2 1 1 3 1 1000000000 3 3
 

Sample Output
1 -1 -1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-20 17:17:31, Gzip enabled