Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.
ContestId |
Name |
Phase |
Frozen |
Duration (Seconds) |
Relative Time |
Start Time |
|---|---|---|---|---|---|---|
| 2005 | Codeforces Round 972 (Div. 2) | FINISHED | False | 7200 | 50081123 | Sept. 14, 2024, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 1233 ) | D | Alter the GCD | PROGRAMMING | binary search data structures divide and conquer dp number theory |
You are given two arrays (a_1, a_2, \ldots, a_n) and (b_1, b_2, \ldots, b_n). You must perform the following operation exactly once : choose any indices (l) and (r) such that (1 \le l \le r \le n); swap (a_i) and (b_i) for all (i) such that (l \leq i \leq r). Find the maximum possible value of (\text{gcd}(a_1, a_2, \ldots, a_n) + \text{gcd}(b_1, b_2, \ldots, b_n)) after performing the operation exactly once. Also find the number of distinct pairs ((l, r)) which achieve the maximum value. In the first line of the input, you are given a single integer (t) ((1 \le t \le 10^5)), the number of test cases. Then the description of each test case follows. In the first line of each test case, you are given a single integer (n) ((1 \le n \le 2 \cdot 10^5)), representing the number of integers in each array. In the next line, you are given (n) integers (a_1, a_2, \ldots, a_n) ((1 \le a_i \le 10^9)) — the elements of the array (a). In the last line, you are given (n) integers (b_1, b_2, \ldots, b_n) ((1 \le b_i \le 10^9)) — the elements of the array (b). The sum of values of (n) over all test cases does not exceed (5 \cdot 10^5). For each test case, output a line with two integers: the maximum value of (\text{gcd}(a_1, a_2, \ldots, a_n) + \text{gcd}(b_1, b_2, \ldots, b_n)) after performing the operation exactly once, and the number of ways. In the first, third, and fourth test cases, there's no way to achieve a higher GCD than (1) in any of the arrays, so the answer is (1 + 1 = 2). Any pair ((l, r)) achieves the same result; for example, in the first test case there are (36) such pairs. In the last test case, you must choose (l = 1), (r = 2) to maximize the answer. In this case, the GCD of the first array is (5), and the GCD of the second array is (1), so the answer is (5 + 1 = 6), and the number of ways is (1). |
| Discussion stream (With Hints) |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 281270738 | vijaypavan34 | D | Sept. 14, 2024, 7:09 p.m. | OK | C++17 (GCC 7-32) | TESTS | 31 | 375 | 3276800 | ||
| 281269430 | parsa333111 | D | Sept. 14, 2024, 6:56 p.m. | OK | C++17 (GCC 7-32) | TESTS | 31 | 390 | 18124800 | ||
| 281257060 | Kilani | D | Sept. 14, 2024, 5:32 p.m. | OK | C++17 (GCC 7-32) | TESTS | 30 | 406 | 3276800 | ||
| 281268344 | altseven | D | Sept. 14, 2024, 6:47 p.m. | OK | C++17 (GCC 7-32) | TESTS | 31 | 437 | 4915200 | ||
| 281296853 | Drice | D | Sept. 15, 2024, 2:49 a.m. | OK | C++17 (GCC 7-32) | TESTS | 37 | 452 | 5939200 | ||
| 281285396 | zeta_quark | D | Sept. 14, 2024, 10:27 p.m. | OK | C++17 (GCC 7-32) | TESTS | 33 | 499 | 9625600 | ||
| 281264216 | PiyushSharma_it_is | D | Sept. 14, 2024, 6:14 p.m. | OK | C++17 (GCC 7-32) | TESTS | 31 | 546 | 242585600 | ||
| 281291108 | yz114514 | D | Sept. 15, 2024, 12:59 a.m. | OK | C++17 (GCC 7-32) | TESTS | 37 | 578 | 3276800 | ||
| 281294262 | yz114514 | D | Sept. 15, 2024, 2:03 a.m. | OK | C++17 (GCC 7-32) | TESTS | 37 | 624 | 3276800 | ||
| 281307411 | Joey_W | D | Sept. 15, 2024, 5:33 a.m. | OK | C++17 (GCC 7-32) | TESTS | 54 | 640 | 51302400 | ||
| 281261569 | fishcathu. | D | Sept. 14, 2024, 5:57 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 343 | 3276800 | ||
| 281255215 | fishcathu. | D | Sept. 14, 2024, 5:24 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 421 | 1638400 | ||
| 281291677 | 415411 | D | Sept. 15, 2024, 1:12 a.m. | OK | C++20 (GCC 13-64) | TESTS | 37 | 421 | 3276800 | ||
| 281295377 | shengdanbucuo | D | Sept. 15, 2024, 2:24 a.m. | OK | C++20 (GCC 13-64) | TESTS | 37 | 421 | 9728000 | ||
| 281262576 | ssd_newbie | D | Sept. 14, 2024, 6:03 p.m. | OK | C++20 (GCC 13-64) | TESTS | 31 | 452 | 9523200 | ||
| 281257464 | justbaka | D | Sept. 14, 2024, 5:34 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 452 | 242688000 | ||
| 281297469 | LOOP0 | D | Sept. 15, 2024, 2:59 a.m. | OK | C++20 (GCC 13-64) | TESTS | 37 | 468 | 24064000 | ||
| 281281126 | wdch | D | Sept. 14, 2024, 9:09 p.m. | OK | C++20 (GCC 13-64) | TESTS | 31 | 483 | 4096000 | ||
| 281267550 | adiyer | D | Sept. 14, 2024, 6:40 p.m. | OK | C++20 (GCC 13-64) | TESTS | 31 | 484 | 3276800 | ||
| 281255735 | fishcathu. | D | Sept. 14, 2024, 5:25 p.m. | OK | C++20 (GCC 13-64) | TESTS | 30 | 499 | 1638400 | ||
| 281255986 | Wobert | D | Sept. 14, 2024, 5:26 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 390 | 22732800 | ||
| 281300383 | 415411 | D | Sept. 15, 2024, 3:48 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 42 | 452 | 3276800 | ||
| 281286162 | pengyantong | D | Sept. 14, 2024, 10:46 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 33 | 671 | 12185600 | ||
| 281291711 | hhhyh | D | Sept. 15, 2024, 1:13 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 37 | 780 | 6144000 | ||
| 281268015 | TheSahib | D | Sept. 14, 2024, 6:44 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 31 | 889 | 35737600 | ||
| 281305177 | yjf1225 | D | Sept. 15, 2024, 5:04 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 48 | 1187 | 9728000 | ||
| 281291147 | SSL_TJH | D | Sept. 15, 2024, 1 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 37 | 1562 | 67584000 | ||
| 281255266 | oversolver | D | Sept. 14, 2024, 5:24 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 1624 | 36761600 | ||
| 281257434 | AliRagab313 | D | Sept. 14, 2024, 5:34 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 30 | 1718 | 28160000 | ||
| 281298235 | NapNa | D | Sept. 15, 2024, 3:13 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 37 | 2124 | 188416000 | ||
| 281302772 | ivanocj | D | Sept. 15, 2024, 4:26 a.m. | OK | Java 21 | TESTS | 43 | 2953 | 2457600 |
Back to search problems