Transmission Door
GCD
Time limit:10000/5000 MS (java/others) Memory limit:65536/65536 K (java/others)
problem Description
Give you a sequence of $N (n≤100,000) $ integers: $a _1,\cdots,a_n (0<a_i≤1000,000,000) $. There is $Q (q≤100,000) $ queries. For each query $l, R $ calculate $\TEXT{GCD} (A_l,,a_{l+1},\cdots,a_r) $ and count the number of pairs$ (l′,r′) <r≤n) $such that $\TEXT{GCD} (a_{l′},a_{l′+1},\cdots,a_{r′}) $ equal $\TEXT{GCD} (A_l,a_{l+1},..., A_{r}) $.
Input
The first line of input contains a number $T $, which stands for the number of test cases you need to solve.
The first line of all case contains a number $N $, denoting the number of integers.
The second line contains $N $ integers, $a _1,\cdots,a_n (0<a_i≤1000,000,000) $.
The third line contains a number $Q $, denoting the number of queries.
For the next $Q $ lines, $i \text{-th}$ line contains, and stand for the $l _i,r_i$, stand for the $i \text{-th}$ quer ies.
Output
Need to output ' case #:t ' at the beginning. (with quotes, t means the number of the "test Case", begin from 1).
For each query, you need to the output of the numbers in a line. The first number stands for $\TEXT{GCD} (a_l,a_{l+1}, \cdots,a_r) $ and the second number stands for the number of pairs$ (l′ , r′) $ such that $\TEXT{GCD} (a_{l′},a_{l′+1},\cdots,a_{r′}) $ equal $\text{gcd} (A_l,a_{l+1},\cdots,a_r) $.
Sample Input
1
5
1 2 4) 6 7
4
1 5
2 4
3 4
4 4
Sample Output
Case #1:
1 8
2 4
2 4
6 1
Author
Hit
Source
Multi-university Training Contest 1
Test instructions
Support query: (1) Interval gcd, (2) gcd value equals K interval number
Solution:
Interval GCD Query line tree can be resolved, in addition to support a single point of modification. But this problem requires support query gcd value equals k interval number, line tree is a bit weak, because this information is probably not very good by merging interval information to get. Let's consider the nature of the interval gcd:
Make $\text{gcd}_r (l) $ indicate, L to r gcd. we
HDU 5726 GCD