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
( 12190 ) D Sum of LDS PROGRAMMING combinatorics dp math

You're given a permutation(^{\text{∗}}) (p_1, \ldots, p_n) such that (\max(p_i, p_{i+1}) > p_{i+2}) for all (1 \leq i \leq n-2). Compute the sum of the length of the longest decreasing subsequence(^{\text{†}}) of the subarray (p_l, p_{l+1}, \ldots, p_r) over all pairs (1 \leq l \leq r \leq n). (^{\text{∗}})A permutation of length (n) is an array consisting of (n) distinct integers from (1) to (n) in arbitrary order. For example, (2,3,1,5,4) is a permutation, but (1,2,2) is not a permutation ((2) appears twice in the array), and (1,3,4) is also not a permutation ((n=3) but there is (4) in the array). (^{\text{†}})Given an array (b) of size (|b|), a decreasing subsequence of length (k) is a sequence of indices (i_1, \ldots, i_k) such that: (1 \leq i_1 < i_2 < \ldots < i_k \leq |b|) (b_{i_1} > b_{i_2} > \ldots > b_{i_k}) Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10\,000)). The description of the test cases follows. The first line of each test case contains a single integer (n) ((3 \leq n \leq 500\,000)). The second line of each test case contains (n) integers (p_1, p_2, \ldots, p_n) ((1 \le p_i \le n), (p_i) are pairwise distinct). It is guaranteed that (\max(p_i, p_{i+1}) > p_{i+2}) for all (1 \leq i \leq n-2). The sum of (n) over all test cases does not exceed (500\,000). For each test case, output the sum over all subarrays of the length of its longest decreasing subsequence. For any array (a), we define (\text{LDS}(a)) as the length of the longest decreasing subsequence of (a). In the first test case, all subarrays are decreasing. In the second one, we have (\text{LDS}(4) = \text{LDS}(3) = \text{LDS}(1) = \text{LDS}(2) = 1) (\text{LDS}(4,3) = \text{LDS}(3,1) = 2, \text{LDS}(1, 2) = 1) $$$\text{LDS}([4,3,1

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
331227606 marscheng D July 28, 2025, 1:12 a.m. OK C++17 (GCC 7-32) TESTS 24 62 4198400
331183531 Terminal_P D July 27, 2025, 4:24 p.m. OK C++17 (GCC 7-32) TESTS 24 77 4096000
331193420 lesnik496 D July 27, 2025, 5:26 p.m. OK C++17 (GCC 7-32) TESTS 24 124 0
331187927 fxfx D July 27, 2025, 4:32 p.m. OK C++17 (GCC 7-32) TESTS 24 124 0
331235077 SF-Manman D July 28, 2025, 2:54 a.m. OK C++17 (GCC 7-32) TESTS 24 124 102400
331238635 Day_Day_Happy D July 28, 2025, 3:40 a.m. OK C++17 (GCC 7-32) TESTS 24 124 102400
331215272 abotaha23 D July 27, 2025, 9:04 p.m. OK C++17 (GCC 7-32) TESTS 24 124 409600
331238741 Day_Day_Happy D July 28, 2025, 3:42 a.m. OK C++17 (GCC 7-32) TESTS 24 124 2048000
331239025 hiuwsss D July 28, 2025, 3:45 a.m. OK C++17 (GCC 7-32) TESTS 24 124 2048000
331240913 MAI_AUR_VOH D July 28, 2025, 4:13 a.m. OK C++17 (GCC 7-32) TESTS 24 124 2252800
331198623 ra_hulYadav669 D July 27, 2025, 6:01 p.m. OK C++20 (GCC 13-64) TESTS 24 62 8192000
331223211 TataneSan D July 27, 2025, 11:57 p.m. OK C++20 (GCC 13-64) TESTS 24 108 102400
331240406 ucode.vn D July 28, 2025, 4:05 a.m. OK C++20 (GCC 13-64) TESTS 24 108 2048000
331247101 DX18581611521 D July 28, 2025, 5:39 a.m. OK C++20 (GCC 13-64) TESTS 24 108 8089600
331242273 ljh537ljh D July 28, 2025, 4:34 a.m. OK C++20 (GCC 13-64) TESTS 24 109 0
331224929 hsiviter D July 28, 2025, 12:35 a.m. OK C++20 (GCC 13-64) TESTS 24 109 0
331238372 5am__Arpit D July 28, 2025, 3:36 a.m. OK C++20 (GCC 13-64) TESTS 24 109 102400
331246860 Jenss D July 28, 2025, 5:36 a.m. OK C++20 (GCC 13-64) TESTS 24 109 102400
331245818 Laoqiang--wiLLAC D July 28, 2025, 5:23 a.m. OK C++20 (GCC 13-64) TESTS 24 109 102400
331234298 Ichinoseyang D July 28, 2025, 2:43 a.m. OK C++20 (GCC 13-64) TESTS 24 109 102400
331233675 424479543 D July 28, 2025, 2:35 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 61 4198400
331233575 424479543 D July 28, 2025, 2:34 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 61 4198400
331241442 L2ngg D July 28, 2025, 4:21 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 108 0
331245900 ABalobanov D July 28, 2025, 5:24 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 108 0
331237052 minhphu2907 D July 28, 2025, 3:19 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 108 0
331245661 xuexiaoyun D July 28, 2025, 5:21 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 108 102400
331199776 philhill D July 27, 2025, 6:10 p.m. OK C++23 (GCC 14-64, msys2) TESTS 24 108 102400
331238473 Hei5enbr3g97 D July 28, 2025, 3:38 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 108 2457600
331245177 Dr_Zhang D July 28, 2025, 5:15 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 108 2457600
331234597 Dr_Zhang D July 28, 2025, 2:47 a.m. OK C++23 (GCC 14-64, msys2) TESTS 24 108 2457600
331183627 James_bond_9089 D July 27, 2025, 4:25 p.m. OK C# 8 TESTS 24 202 36454400
331206933 Harin2205 D July 27, 2025, 7:19 p.m. OK GNU C11 TESTS 24 109 2048000
331210783 i-am-vivek D July 27, 2025, 8:04 p.m. OK GNU C11 TESTS 24 109 6144000
331188391 herit_desai D July 27, 2025, 4:33 p.m. OK GNU C11 TESTS 24 140 2048000
331210512 i-am-vivek D July 27, 2025, 8:01 p.m. OK GNU C11 TESTS 24 140 6144000
331184151 pengin_2000 D July 27, 2025, 4:26 p.m. OK GNU C11 TESTS 24 156 7987200
331238399 xhgybbybz D July 28, 2025, 3:37 a.m. OK Go TESTS 24 202 8089600
331240385 xhgybbybz D July 28, 2025, 4:05 a.m. OK Go TESTS 24 202 12288000
331239226 xhgybbybz D July 28, 2025, 3:48 a.m. OK Go TESTS 24 233 8192000
331182910 lupunish D July 27, 2025, 4:23 p.m. OK Java 21 TESTS 24 374 4915200
331187608 GoodBoy20 D July 27, 2025, 4:32 p.m. OK Java 21 TESTS 24 374 6656000
331212948 yuvrajye D July 27, 2025, 8:29 p.m. OK Java 21 TESTS 24 421 6758400
331193776 testtest111ksjfrdvn D July 27, 2025, 5:28 p.m. OK Java 21 TESTS 24 514 35020800
331185799 Sudip809 D July 27, 2025, 4:29 p.m. OK Java 21 TESTS 24 561 32972800
331197609 sad_truant D July 27, 2025, 5:53 p.m. OK Java 21 TESTS 24 608 48128000
331189187 Anvesh_2095 D July 27, 2025, 4:34 p.m. OK Java 21 TESTS 24 968 1331200
331196366 priyaroy3370 D July 27, 2025, 5:45 p.m. OK Java 21 TESTS 24 999 921600
331188185 Samyak_07 D July 27, 2025, 4:33 p.m. OK Java 21 TESTS 24 999 1228800
331189021 luckyN1 D July 27, 2025, 4:34 p.m. OK Java 21 TESTS 24 1062 2048000
331187071 abhinav_26104 D July 27, 2025, 4:31 p.m. OK Java 8 TESTS 24 265 11776000
331185607 rutul21 D July 27, 2025, 4:28 p.m. OK Java 8 TESTS 24 281 14745600
331201952 kasiru_69 D July 27, 2025, 6:29 p.m. OK Java 8 TESTS 24 374 49049600
331242214 SilverBullet4869 D July 28, 2025, 4:33 a.m. OK Java 8 TESTS 24 671 0
331207684 anshika_bansal2430 D July 27, 2025, 7:27 p.m. OK Java 8 TESTS 24 686 3788800
331188029 saicharangopisetty23 D July 27, 2025, 4:32 p.m. OK Java 8 TESTS 24 796 0
331182600 maverick_575 D July 27, 2025, 4:22 p.m. OK Java 8 TESTS 24 812 0
331183342 ShivamChouhan D July 27, 2025, 4:24 p.m. OK Java 8 TESTS 24 828 0
331194720 L-S-S D July 27, 2025, 5:34 p.m. OK Kotlin 1.9 TESTS 24 577 52224000
331188822 Haiderekarar694209 D July 27, 2025, 4:34 p.m. OK PyPy 3 TESTS 24 499 34406400
331183603 o_e_a_e_o_e_e_e_a_e D July 27, 2025, 4:25 p.m. OK PyPy 3 TESTS 24 546 32870400
331226767 taowdy D July 28, 2025, 12:59 a.m. OK PyPy 3-64 TESTS 24 187 45465600
331230094 hirose2020 D July 28, 2025, 1:49 a.m. OK PyPy 3-64 TESTS 24 187 47923200
331187217 the_seal D July 27, 2025, 4:31 p.m. OK PyPy 3-64 TESTS 24 187 47923200
331184400 mpatel D July 27, 2025, 4:26 p.m. OK PyPy 3-64 TESTS 24 187 48435200
331245321 yejordan8888 D July 28, 2025, 5:17 a.m. OK PyPy 3-64 TESTS 24 202 44236800
331240333 LightHouse1 D July 28, 2025, 4:04 a.m. OK PyPy 3-64 TESTS 24 202 47718400
331233137 smilences D July 28, 2025, 2:28 a.m. OK PyPy 3-64 TESTS 24 202 48435200
331249371 maruf_khan96 D July 28, 2025, 6:04 a.m. OK PyPy 3-64 TESTS 24 202 60211200
331232301 golomb D July 28, 2025, 2:17 a.m. OK PyPy 3-64 TESTS 24 203 45465600
331201779 SrEy_P-0-7 D July 27, 2025, 6:27 p.m. OK PyPy 3-64 TESTS 24 203 47411200
331188390 basakdiwakar D July 27, 2025, 4:33 p.m. OK Python 3 TESTS 24 296 52531200
331186066 lowest_contribution D July 27, 2025, 4:29 p.m. OK Python 3 TESTS 24 296 54067200
331183565 OnShoreApple D July 27, 2025, 4:24 p.m. OK Python 3 TESTS 24 327 57651200
331187158 tanishasingh7 D July 27, 2025, 4:31 p.m. OK Python 3 TESTS 24 342 52531200
331211050 cioppy D July 27, 2025, 8:08 p.m. OK Python 3 TESTS 24 359 54169600
331183750 rishi_140603 D July 27, 2025, 4:25 p.m. OK Python 3 TESTS 24 359 54272000
331220010 ChatIsThisReal D July 27, 2025, 10:41 p.m. OK Python 3 TESTS 24 389 54067200
331187510 Sai-Bhargav D July 27, 2025, 4:31 p.m. OK Python 3 TESTS 24 405 54169600
331186828 R.Gnanesh D July 27, 2025, 4:31 p.m. OK Python 3 TESTS 24 405 54169600
331246308 kareem_un_nawaz D July 28, 2025, 5:29 a.m. OK Python 3 TESTS 24 468 53862400

remove filters

Back to search problems