Codeforces Round 1089 (Div. 2)

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
2210 Codeforces Round 1089 (Div. 2) FINISHED False 8100 1610723 March 29, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 2024 ) C2 A Simple GCD Problem (Hard Version) PROGRAMMING dp greedy number theory

This is the hard version of the problem. The difference between the versions is that in this version, (1 \leq n \leq 5 \cdot 10^{4}), (1 \leq b_i \leq 10^{9}) for (1 \leq i \leq n), and the time limit is (6) seconds. Note that a solution for one version does not necessarily solve the other version. You can hack only if you solved all versions of this problem. You are given two arrays (a) and (b) of length (n). For each index (i) ((1 \le i \le n)) of array (a), you can perform the following operation at most once : choose an arbitrary integer (m) ((\mathbf{m \neq a_i})) such that (1 \leq m \leq b_i), and set (a_i := m). Let the array after performing all the operations be (a'). You can only perform operations in such a way that the following condition holds: For all (1\leq l \lt r\leq n), (\operatorname{gcd}(a_l,a_{l+1},\ldots,{a_r})=\operatorname{gcd}(a'_l,a'_{l+1},\ldots,a'_r)) Here, (\gcd(x, y)) denotes the greatest common divisor (GCD) of integers (x) and (y). You have to determine the maximum number of operations that can be performed while ensuring that the condition remains satisfied. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each test case contains an integer (n) ((2 \leq n \leq 5\cdot 10^4)) — the length of (a). The following line of each test case contains (n) space-separated integers (a_1, a_2, \ldots, a_n) ((1 \leq a_i \leq 10^9)). The next line of each test case contains (n) space-separated integers (b_1, b_2, \ldots, b_n) ( (1 \le b_i \le 10^9) ). It is guaranteed that the sum of (n) over all test cases does not exceed (5\cdot 10^4). For each test case, output the maximum number of operations which can be done. In the first test, since the gcd of all subarrays is (1), we can cha

Tutorials

Codeforces Round 1089 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
368805340 _Equinox C2 March 30, 2026, 4:57 a.m. OK C# 13 TESTS 27 3359 17817600
368764806 ok12 C2 March 29, 2026, 4:41 p.m. OK C# 13 TESTS 20 3562 64307200

remove filters

Back to search problems