Codeforces Round 1095 (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
2226 Codeforces Round 1095 (Div. 2) FINISHED False 8100 1178664 April 28, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 795 ) E Mental Monumental (Hard Version) PROGRAMMING data structures greedy math

This is the hard version of this problem. In this version, you are required to find the values of (f(\cdot)) for each prefix of (a). For any array (c_1, c_2, \ldots, c_m), we define (f(c)) as the maximum possible (\operatorname{mex}(c))(^{\text{∗}}) that can be achieved by performing the following operation exactly once: Choose an integer array (b_1, b_2, \ldots, b_m) such that (b_i \ge 1) for all (1 \le i \le m); Set (c_i := c_i \, \bmod \, b_i)(^{\text{†}}) for every (1 \le i \le m). You are given an array (a) consisting of (n) non-negative integers. For each prefix (a^{(i)} = a_1, a_2, \ldots, a_i), determine the value of (f(a^{(i)})). (^{\text{∗}})(\operatorname{mex}(c)) denotes the minimum excluded (MEX) of the integers in (c). For example, (\operatorname{mex}(2,2,1)=0) because (0) does not belong to the array, and (\operatorname{mex}(0,3,1,2)=4) because (0), (1), (2), and (3) appear in the array, but (4) does not. (^{\text{†}})(u \bmod v) denotes the remainder from dividing (u) by (v). 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 testcase contains a single integer (n) ((1 \le n \le 2 \cdot 10^5)) — the length of the array (a). The second line of each testcase contains (n) integers (a_1, a_2, \ldots, a_n) ((0 \le a_i \le 10^6)) — the elements of the array (a). It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). It is guaranteed that the sum of (\max(a_1,a_2,\ldots,a_n)) over all test cases does not exceed (10^6). For each testcase, output (n) integers — where the (i)-th integer represents the value of (f(a_1, a_2, \ldots, a_i)). Consider the first testcase, (a^{(1)} = 0), choosin

Tutorials

Codeforces Round 1095 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
372865406 caffeine2ac E April 28, 2026, 4:23 p.m. OK C# 13 TESTS 20 328 28979200
372907711 potato167 E April 29, 2026, 4:27 a.m. OK C++17 (GCC 7-32) TESTS 20 156 21913600
372872392 niu-zh E April 28, 2026, 4:49 p.m. OK C++17 (GCC 7-32) TESTS 20 171 7270400
372862008 Surge568 E April 28, 2026, 4:11 p.m. OK C++17 (GCC 7-32) TESTS 20 171 44134400
372868153 mahirgupta1221 E April 28, 2026, 4:33 p.m. OK C++17 (GCC 7-32) TESTS 20 203 6041600
372882542 _.rajababu E April 28, 2026, 6:35 p.m. OK C++17 (GCC 7-32) TESTS 20 203 9011200
372864411 mnx_007 E April 28, 2026, 4:19 p.m. OK C++17 (GCC 7-32) TESTS 20 234 11264000
372875926 MCPlayer542 E April 28, 2026, 5:31 p.m. OK C++17 (GCC 7-32) TESTS 20 234 36966400
372867926 daremo E April 28, 2026, 4:32 p.m. OK C++17 (GCC 7-32) TESTS 20 234 36966400
372870064 evgen2571 E April 28, 2026, 4:40 p.m. OK C++17 (GCC 7-32) TESTS 20 250 1126400
372878386 loveax E April 28, 2026, 5:55 p.m. OK C++17 (GCC 7-32) TESTS 20 250 3379200
372869539 howD E April 28, 2026, 4:38 p.m. OK C++20 (GCC 13-64) TESTS 20 156 9523200
372856072 Misuki E April 28, 2026, 3:52 p.m. OK C++20 (GCC 13-64) TESTS 20 187 8294400
372867358 flame_leaf E April 28, 2026, 4:30 p.m. OK C++20 (GCC 13-64) TESTS 20 218 32972800
372904995 wabca E April 29, 2026, 3:23 a.m. OK C++20 (GCC 13-64) TESTS 20 218 40140800
372867829 hexahydride E April 28, 2026, 4:32 p.m. OK C++20 (GCC 13-64) TESTS 20 218 67174400
372904265 zhy1206 E April 29, 2026, 3:05 a.m. OK C++20 (GCC 13-64) TESTS 20 218 137932800
372867691 nwblanton E April 28, 2026, 4:31 p.m. OK C++20 (GCC 13-64) TESTS 20 234 1945600
372863459 kotatsugame E April 28, 2026, 4:16 p.m. OK C++20 (GCC 13-64) TESTS 20 234 6451200
372868586 for_dsa123 E April 28, 2026, 4:35 p.m. OK C++20 (GCC 13-64) TESTS 20 234 32153600
372868632 ByeWorld512 E April 28, 2026, 4:35 p.m. OK C++20 (GCC 13-64) TESTS 20 234 96256000
372878553 Wawi E April 28, 2026, 5:57 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 109 4198400
372870814 Wleaf E April 28, 2026, 4:43 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 140 4198400
372859065 Kude E April 28, 2026, 4:02 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 156 5734400
372864328 Hall-s_Theorem E April 28, 2026, 4:19 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 156 25804800
372872075 ivatopuria E April 28, 2026, 4:48 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 171 5017600
372888118 424479543 E April 28, 2026, 7:39 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 171 5324800
372871190 samsoom E April 28, 2026, 4:45 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 171 39424000
372856424 xiaoxiaobaozi E April 28, 2026, 3:53 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 187 2560000
372878091 abududu E April 28, 2026, 5:52 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 187 5017600
372869876 _WD_ E April 28, 2026, 4:40 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 187 6451200
372870308 Gassa E April 28, 2026, 4:41 p.m. OK D TESTS 20 812 42496000
372866937 codecrasher_ E April 28, 2026, 4:29 p.m. OK Go TESTS 20 375 32460800
372863600 kartikjaju5 E April 28, 2026, 4:17 p.m. OK Java 21 TESTS 20 406 14131200
372894996 man-ray E April 28, 2026, 9:55 p.m. OK Java 21 TESTS 20 625 37580800
372857993 mctikhapaneer E April 28, 2026, 3:58 p.m. OK Java 21 TESTS 20 656 35020800
372861748 pieande E April 28, 2026, 4:10 p.m. OK Java 21 TESTS 20 656 43417600
372889523 uttaran_das E April 28, 2026, 7:59 p.m. OK Java 21 TESTS 20 687 12902400
372867269 yadavrajakran854 E April 28, 2026, 4:30 p.m. OK Java 21 TESTS 20 906 9318400
372868233 taran_1407 E April 28, 2026, 4:33 p.m. OK Java 21 TESTS 20 968 37068800
372863610 Moltisanti E April 28, 2026, 4:17 p.m. OK Java 21 TESTS 20 1078 18636800
372869726 anushkashanker424 E April 28, 2026, 4:39 p.m. OK Java 21 TESTS 20 1093 12902400
372858666 gagan_singh E April 28, 2026, 4 p.m. OK Java 8 TESTS 20 687 11878400
372857116 yg.margo E April 28, 2026, 3:55 p.m. OK Kotlin 2.2 TESTS 20 281 24064000
372866570 bitplease_ E April 28, 2026, 4:27 p.m. OK Node.js TESTS 20 593 47206400
372867472 Evg_MaxProDota E April 28, 2026, 4:30 p.m. OK PyPy 3-64 TESTS 20 656 42188800
372893163 hugoback01 E April 28, 2026, 9:06 p.m. OK PyPy 3-64 TESTS 20 812 48640000
372859339 Little_Sheep_Yawn E April 28, 2026, 4:02 p.m. OK PyPy 3-64 TESTS 20 921 45056000
372858055 Nikrien E April 28, 2026, 3:58 p.m. OK PyPy 3-64 TESTS 20 921 62566400
372900296 smilences E April 29, 2026, 1:12 a.m. OK PyPy 3-64 TESTS 20 1218 54169600
372900370 smilences E April 29, 2026, 1:14 a.m. OK PyPy 3-64 TESTS 20 1250 51507200
372857610 Sacred_Conqueror E April 28, 2026, 3:57 p.m. OK PyPy 3-64 TESTS 20 1390 61747200
372890235 Z_actuary E April 28, 2026, 8:11 p.m. OK PyPy 3-64 TESTS 20 1812 102912000
372861728 dsarkar E April 28, 2026, 4:10 p.m. OK PyPy 3-64 TESTS 20 2093 72396800
372871000 wasbee E April 28, 2026, 4:44 p.m. OK PyPy 3-64 TESTS 20 2843 59801600
372865993 trycatchcry E April 28, 2026, 4:25 p.m. OK Rust 2024 TESTS 20 281 40550400
372871313 cvs-650 E April 28, 2026, 4:45 p.m. OK Rust 2024 TESTS 20 328 50380800
372884136 kushagrakaneki E April 28, 2026, 6:53 p.m. OK Rust 2024 TESTS 20 796 148787200

remove filters

Back to search problems