Codeforces Round 1024 (Div. 1)

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
2101 Codeforces Round 1024 (Div. 1) FINISHED False 9000 29431523 May 11, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 2251 ) C 23 Kingdom PROGRAMMING binary search data structures greedy ternary search two pointers

The distance of a value (x) in an array (c), denoted as (d_x(c)), is defined as the largest gap between any two occurrences of (x) in (c). Formally, (d_x(c) = \max(j - i)) over all pairs (i < j) where (c_i = c_j = x). If (x) appears only once or not at all in (c), then (d_x(c) = 0). The beauty of an array is the sum of the distances of each distinct value in the array. Formally, the beauty of an array (c) is equal to (\sum\limits_{1\le x\le n} d_x(c)). Given an array (a) of length (n), an array (b) is nice if it also has length (n) and its elements satisfy (1\le b_i\le a_i) for all (1\le i\le n). Your task is to find the maximum possible beauty of any nice array. 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 a single integer (n) ((1\le n\le 2\cdot10^5)) — the length of array (a). The second line of each test case contains (n) integers (a_1,a_2,\ldots,a_n) ((1\le a_i\le n)) — the elements of array (a). It is guaranteed that the sum of (n) over all test cases does not exceed (2\cdot10^5). For each test case, output a single integer representing the maximum possible beauty among all nice arrays. In the first test case, if (b = 1, 2, 1, 2), then (d_1(b) = 3 - 1 = 2) and (d_2(b) = 4 - 2 = 2), resulting in a beauty of (2 + 2 = 4). It can be proven that there are no nice arrays with a beauty greater than (4). In the second test case, both (b = 1, 1) and (b = 2, 2) are valid solutions with a beauty of (1). In the third test case, if (b = 1, 2, 1, 4, 1, 2, 1, 1, 1, 2) with (d_1(b) = 9 - 1 = 8), (d_2(b) = 10 - 2 = 8), and (d_4(b) = 0), resulting in a beauty of (16).

Tutorials

142788

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
319238702 Potassium C May 11, 2025, 3:10 p.m. OK C++17 (GCC 7-32) TESTS 69 140 1945600
319324678 zhuzc C May 12, 2025, 4:14 a.m. OK C++17 (GCC 7-32) TESTS 69 140 7270400
319270147 Muelsyse C May 11, 2025, 4:03 p.m. OK C++17 (GCC 7-32) TESTS 69 155 7270400
319253723 KroosTheKeenGlint C May 11, 2025, 3:35 p.m. OK C++17 (GCC 7-32) TESTS 69 171 9216000
319238169 MiracleAutomaton C May 11, 2025, 3:09 p.m. OK C++17 (GCC 7-32) TESTS 69 187 2457600
319269249 masonpop C May 11, 2025, 4:01 p.m. OK C++17 (GCC 7-32) TESTS 69 233 7987200
319255421 AliShahali1382 C May 11, 2025, 3:38 p.m. OK C++17 (GCC 7-32) TESTS 69 234 13312000
319288467 xiaoziya C May 11, 2025, 4:58 p.m. OK C++17 (GCC 7-32) TESTS 69 249 13004800
319278183 QZJ666 C May 11, 2025, 4:25 p.m. OK C++17 (GCC 7-32) TESTS 69 249 15257600
319310864 autumoon C May 11, 2025, 10:17 p.m. OK C++17 (GCC 7-32) TESTS 69 249 101068800
319320564 Tong_Yuxin C May 12, 2025, 3:02 a.m. OK C++20 (GCC 13-64) TESTS 69 78 1638400
319326754 yeminghan C May 12, 2025, 4:49 a.m. OK C++20 (GCC 13-64) TESTS 69 108 8089600
319253681 Natsuzora C May 11, 2025, 3:35 p.m. OK C++20 (GCC 13-64) TESTS 69 109 819200
319269868 FISHKI_RABOTAUT C May 11, 2025, 4:03 p.m. OK C++20 (GCC 13-64) TESTS 69 124 2764800
319299021 fishcathu C May 11, 2025, 6:43 p.m. OK C++20 (GCC 13-64) TESTS 69 124 3276800
319263014 awoo C May 11, 2025, 3:47 p.m. OK C++20 (GCC 13-64) TESTS 69 124 3481600
319268643 aastik231205 C May 11, 2025, 4 p.m. OK C++20 (GCC 13-64) TESTS 69 124 4403200
319294871 NickMish C May 11, 2025, 6:01 p.m. OK C++20 (GCC 13-64) TESTS 69 124 7680000
319243729 BalintR C May 11, 2025, 3:17 p.m. OK C++20 (GCC 13-64) TESTS 69 140 1638400
319250081 arnold518 C May 11, 2025, 3:28 p.m. OK C++20 (GCC 13-64) TESTS 69 171 13721600
319295430 ecnerwala C May 11, 2025, 6:06 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 108 102400
319237746 while_zeze C May 11, 2025, 3:08 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 108 18022400
319257039 raincity C May 11, 2025, 3:42 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 109 1638400
319285569 egge C May 11, 2025, 4:49 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 124 102400
319242494 nuip C May 11, 2025, 3:15 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 124 102400
319278554 koukanni C May 11, 2025, 4:26 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 124 2867200
319277931 radoslav11 C May 11, 2025, 4:24 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 124 8089600
319278377 42i196 C May 11, 2025, 4:26 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 124 11264000
319298390 djm03178 C May 11, 2025, 6:36 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 125 1638400
319276417 biximo C May 11, 2025, 4:20 p.m. OK C++23 (GCC 14-64, msys2) TESTS 69 140 2457600
319298895 rainboy C May 11, 2025, 6:41 p.m. OK GNU C11 TESTS 69 124 4096000
319288538 rainboy C May 11, 2025, 4:58 p.m. OK GNU C11 TESTS 69 124 8294400
319325282 muradbhai C May 12, 2025, 4:25 a.m. OK GNU C11 TESTS 69 140 4915200
319325020 muradbhai C May 12, 2025, 4:21 a.m. OK GNU C11 TESTS 69 140 4915200
319285045 ghj1222 C May 11, 2025, 4:47 p.m. OK GNU C11 TESTS 69 202 39731200
319331578 lyongwolf C May 12, 2025, 5:48 a.m. OK Java 21 TESTS 69 827 21299200
319332053 lyongwolf C May 12, 2025, 5:53 a.m. OK Java 21 TESTS 69 968 19660800
319332182 lyongwolf C May 12, 2025, 5:55 a.m. OK Java 21 TESTS 69 999 8704000
319331997 lyongwolf C May 12, 2025, 5:53 a.m. OK Java 21 TESTS 69 1015 48947200
319264135 golions C May 11, 2025, 3:50 p.m. OK Java 8 TESTS 69 1218 23552000
319239297 Tlatoani C May 11, 2025, 3:10 p.m. OK Kotlin 1.9 TESTS 69 842 31232000
319244095 toam C May 11, 2025, 3:18 p.m. OK PyPy 3-64 TESTS 69 468 37171200
319279561 bribritt C May 11, 2025, 4:29 p.m. OK PyPy 3-64 TESTS 69 874 45056000
319267008 smilences C May 11, 2025, 3:56 p.m. OK PyPy 3-64 TESTS 69 1030 28467200
319271114 Alex239 C May 11, 2025, 4:06 p.m. OK PyPy 3-64 TESTS 69 1139 36864000
319284934 plevande C May 11, 2025, 4:47 p.m. OK PyPy 3-64 TESTS 69 1217 83865600
319277787 028 C May 11, 2025, 4:24 p.m. OK PyPy 3-64 TESTS 69 1327 37888000
319279736 16777216 C May 11, 2025, 4:30 p.m. OK PyPy 3-64 TESTS 69 2265 36556800
319264676 harurun4635 C May 11, 2025, 3:51 p.m. OK PyPy 3-64 TESTS 69 2843 28057600
319262506 eepsilon C May 11, 2025, 3:46 p.m. OK PyPy 3-64 TESTS 69 3077 39116800
319282611 chinerist C May 11, 2025, 4:39 p.m. OK PyPy 3-64 TESTS 69 3327 121651200
319332184 shashanksp851 C May 12, 2025, 5:55 a.m. OK Python 3 TESTS 69 468 45977600
319243371 Egor C May 11, 2025, 3:17 p.m. OK Rust 2021 TESTS 69 171 10752000
319247631 sansen C May 11, 2025, 3:24 p.m. OK Rust 2021 TESTS 69 187 7987200
319326025 Dpkasd_12 C May 12, 2025, 4:37 a.m. OK Rust 2021 TESTS 69 202 12185600
319275172 darkkcyan C May 11, 2025, 4:16 p.m. OK Rust 2021 TESTS 69 280 15462400

remove filters

Back to search problems