Codeforces Round 1011 (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
2085 Codeforces Round 1011 (Div. 2) FINISHED False 7200 33751523 March 22, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 514 ) F2 Serval and Colorful Array (Hard Version) PROGRAMMING data structures greedy

This is the hard version of the problem. The difference between the versions is that in this version, (n\le 4\cdot 10^5). You can hack only if you solved all versions of this problem. Serval has a magic number (k) ((k\ge 2)). We call an array (r) colorful if and only if: The length of (r) is (k), and Each integer between (1) and (k) appears exactly once in (r). You are given an array (a) consisting of (n) integers between (1) and (k). It is guaranteed that each integer between (1) and (k) appears in (a) at least once. You can perform the following operation on (a): Choose an index (i) ((1\le i < n)), then swap (a_i) and (a_{i+1}). Find the minimum number of operations needed to make at least one subarray(^{\text{∗}}) of (a) colorful . It can be shown that this is always possible under the constraints of the problem. (^{\text{∗}})An array (b) is a subarray of an array (a) if (b) can be obtained from (a) by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 1000)). The description of the test cases follows. The first line of each test case contains two integers (n) and (k) ((2\leq k\leq n\leq 4\cdot 10^5)) — the length of the array (a) and Serval's magic number. The second line contains (n) integers (a_1, a_2, \ldots, a_n) ((1\leq a_i\leq k)) — the elements of the array (a). It is guaranteed that each integer between (1) and (k) appears in (a) at least once. It is guaranteed that the sum of (n) over all test cases does not exceed (4\cdot 10^5). For each test case, output a single integer — the minimum number of operations needed to make at least one subarray of (a) colorful . In the first test case

Tutorials

Codeforces Round #1011 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
311954557 sheep32768 F2 March 23, 2025, 4:34 a.m. OK C++17 (GCC 7-32) TESTS 60 140 12902400
311968646 zhouyan_ F2 March 23, 2025, 5:45 a.m. OK C++17 (GCC 7-32) TESTS 60 171 4915200
311952158 ywjylx F2 March 23, 2025, 4:01 a.m. OK C++17 (GCC 7-32) TESTS 60 218 13004800
311933282 Sparkle_Twilight F2 March 22, 2025, 10:11 p.m. OK C++17 (GCC 7-32) TESTS 60 389 19148800
311932504 EL_DOKSH F2 March 22, 2025, 10:02 p.m. OK C++17 (GCC 7-32) TESTS 60 389 19148800
311944832 mandy0109 F2 March 23, 2025, 1:58 a.m. OK C++17 (GCC 7-32) TESTS 60 453 9625600
311940326 abeker F2 March 23, 2025, 12:01 a.m. OK C++17 (GCC 7-32) TESTS 60 530 269721600
311939588 tin.le2 F2 March 22, 2025, 11:41 p.m. OK C++20 (GCC 13-64) TESTS 60 124 102400
311956334 xly_tyty F2 March 23, 2025, 4:56 a.m. OK C++20 (GCC 13-64) TESTS 60 124 24064000
311957968 furry F2 March 23, 2025, 5:14 a.m. OK C++20 (GCC 13-64) TESTS 60 203 21811200
311912663 aniketcodeforces F2 March 22, 2025, 6:56 p.m. OK C++20 (GCC 13-64) TESTS 60 218 18329600
311938148 Rayo F2 March 22, 2025, 11:15 p.m. OK C++20 (GCC 13-64) TESTS 60 281 5120000
311938102 Rayo F2 March 22, 2025, 11:14 p.m. OK C++20 (GCC 13-64) TESTS 60 281 5120000
311925190 Boy.Man F2 March 22, 2025, 8:54 p.m. OK C++20 (GCC 13-64) TESTS 60 311 20684800
311911465 kotatsugame F2 March 22, 2025, 6:45 p.m. OK C++20 (GCC 13-64) TESTS 60 311 20684800
311954965 ella09 F2 March 23, 2025, 4:39 a.m. OK C++20 (GCC 13-64) TESTS 60 312 4812800
311942128 brianxi F2 March 23, 2025, 12:53 a.m. OK C++20 (GCC 13-64) TESTS 60 500 9728000

remove filters

Back to search problems