# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
Name |
---|
If we replace each element of the array with all its divisors, then query for the maximum GCD is query on maximum element of subarray, that meets twice. For solve this problem we can use a technique similar to DQUERY.
We will solve this problem offline. First, create event of two type:
For generate query of first type we need factorize every elements of array $$$a$$$ and for every divisor $$$d$$$ remember index of element, that divide into $$$d$$$. This can be done with std::map.
Sort event first by $$$r$$$, than by type.
Iterate on event and if handle first type we need to do $$$C_l = max(C_l, d)$$$, if handle second type event we need to find $$$max(C_l, C_{l+1},...,C_r)$$$ — it's answer for $$$i$$$-th query. This can be done with data structure segment tree or BIT.
Calculate complexity. We factorize all elements of array $$$O(n \sqrt A)$$$, each divisor we update in map $$$O(n \sqrt[3] A \cdot log(n \sqrt[3] A)) $$$ and use segment tree for answer on query $$$O((q + n \sqrt[3] A)\cdot log(n))$$$.
Total complexity this solution is $$$O(n \sqrt A + n \sqrt[3] A \cdot log(n \sqrt[3] A) + q \cdot log(n))$$$. My solution work in 0.6 seconds.
Thanks a lot. Fortin
You can read editorial here https://discussed.codechef.com/questions/125148/gqr-editorial