Codeforces Round 1039 (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
2128 Codeforces Round 1039 (Div. 2) FINISHED False 7200 22778723 July 27, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 788 ) E2 Submedians (Hard Version) PROGRAMMING binary search constructive algorithms data structures two pointers

This is the hard version of the problem. The only difference is that in this version, you are asked to find a subarray for all submedians . You can make hacks only if both versions of the problem are solved. An integer (v) is a median of an array (b) of length (m) if and only if: (v) is greater than or equal to at least (\lceil \frac{m}{2} \rceil) elements of the array, and (v) is less than or equal to at least (\lceil \frac{m}{2} \rceil) elements of the array. the only median of (9, 3, 7) is (7), the medians of (5, 3, 7, 9) are (5), (6), and (7), and the only median of (2, 2, 2) is (2). You're given an integer (k) and an array (a_1, \ldots, a_n) of integers between (1) and (n). An integer (v) from (1) to (n) is said to be a submedian if there exists at least one pair of indices ((l, r)) such that (1 \leq l \leq r \leq n), (r - l + 1 \geq k), (v) is a median of the subarray (a_l, \ldots, a_r). Find all submedians and for each of them, find any corresponding pair of indices ((l, r)). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 50\,000)). The description of the test cases follows. The first line of each test case contains two integers (n) and (k) ((1 \leq k \leq n \leq 300\,000)). The second line of each test case contains (n) integers (a_1, a_2, \ldots, a_n) ((1 \leq a_i \leq n)). It is guaranteed that the sum of (n) over all test cases doesn't exceed (300\,000). For each test case, output your answer in the following format. On the first line, output (c), the number of submedians . On the (i)-th of the following (c) lines, output three integers (v_i), (l_i), and (r_i) such that (r_i - l_i + 1 \geq k), and (v_i) is one of the medians of the subarray (a_{l_i}, \ldots, a_{r_i}). Each submedian should be

Tutorials

Codeforces Round #1039 — Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
331222985 TataneSan E2 July 27, 2025, 11:51 p.m. OK C++17 (GCC 7-32) TESTS 23 296 819200
331216683 lwm7708 E2 July 27, 2025, 9:30 p.m. OK C++17 (GCC 7-32) TESTS 23 327 10444800
331193447 leela_0 E2 July 27, 2025, 5:26 p.m. OK C++17 (GCC 7-32) TESTS 23 358 18022400
331218975 Tomato_Cultivator E2 July 27, 2025, 10:21 p.m. OK C++17 (GCC 7-32) TESTS 23 436 18432000
331185046 JOliva E2 July 27, 2025, 4:27 p.m. OK C++17 (GCC 7-32) TESTS 23 484 22016000
331240572 CardboardTank E2 July 28, 2025, 4:08 a.m. OK C++17 (GCC 7-32) TESTS 23 500 21196800
331224307 MoriorInvictus E2 July 28, 2025, 12:25 a.m. OK C++17 (GCC 7-32) TESTS 23 562 11264000
331238841 qwerdkr E2 July 28, 2025, 3:43 a.m. OK C++17 (GCC 7-32) TESTS 23 609 16179200
331241313 lock_ E2 July 28, 2025, 4:19 a.m. OK C++17 (GCC 7-32) TESTS 23 640 16588800
331192585 Voyagercf E2 July 27, 2025, 5:23 p.m. OK C++17 (GCC 7-32) TESTS 23 640 18432000
331241426 Tianheng7777777 E2 July 28, 2025, 4:21 a.m. OK C++20 (GCC 13-64) TESTS 23 140 1126400
331196032 Husanboy E2 July 27, 2025, 5:42 p.m. OK C++20 (GCC 13-64) TESTS 23 280 4812800
331230835 wenqizhi E2 July 28, 2025, 1:59 a.m. OK C++20 (GCC 13-64) TESTS 23 281 8294400
331206651 ahmetalp E2 July 27, 2025, 7:16 p.m. OK C++20 (GCC 13-64) TESTS 23 327 19148800
331199080 bestial-42-centroids E2 July 27, 2025, 6:05 p.m. OK C++20 (GCC 13-64) TESTS 23 327 25804800
331228975 chenhongrui E2 July 28, 2025, 1:32 a.m. OK C++20 (GCC 13-64) TESTS 23 342 24064000
331183476 rt3 E2 July 27, 2025, 4:24 p.m. OK C++20 (GCC 13-64) TESTS 23 342 26931200
331185661 noya2 E2 July 27, 2025, 4:28 p.m. OK C++20 (GCC 13-64) TESTS 23 358 21196800
331238746 PsychoPinkQ E2 July 28, 2025, 3:42 a.m. OK C++20 (GCC 13-64) TESTS 23 375 20172800
331239613 Swan416 E2 July 28, 2025, 3:53 a.m. OK C++20 (GCC 13-64) TESTS 23 421 2355200
331198724 Fantasy_Blue E2 July 27, 2025, 6:02 p.m. OK C++23 (GCC 14-64, msys2) TESTS 23 171 3686400
331235752 gxd E2 July 28, 2025, 3:02 a.m. OK C++23 (GCC 14-64, msys2) TESTS 23 186 7270400
331230927 424479543 E2 July 28, 2025, 2 a.m. OK C++23 (GCC 14-64, msys2) TESTS 23 218 2969600
331198871 Fantasy_Blue E2 July 27, 2025, 6:03 p.m. OK C++23 (GCC 14-64, msys2) TESTS 23 218 3686400
331247063 crocell001 E2 July 28, 2025, 5:38 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 233 1331200
331210098 UFEQ E2 July 27, 2025, 7:56 p.m. OK C++23 (GCC 14-64, msys2) TESTS 23 249 1228800
331198772 Fantasy_Blue E2 July 27, 2025, 6:02 p.m. OK C++23 (GCC 14-64, msys2) TESTS 23 264 3686400
331197689 415411 E2 July 27, 2025, 5:54 p.m. OK C++23 (GCC 14-64, msys2) TESTS 23 265 12390400
331198620 415411 E2 July 27, 2025, 6:01 p.m. OK C++23 (GCC 14-64, msys2) TESTS 23 280 12288000
331196582 415411 E2 July 27, 2025, 5:46 p.m. OK C++23 (GCC 14-64, msys2) TESTS 23 296 12288000

remove filters

Back to search problems