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.
Problems
B'You are given a permutation p_1, p_2, ... , p_n of [1, 2, ... , n] . You can perform the following operation some (possibly 0 ) times: Sort the permutation in at most 10^6 operations. You do not need to minimize the number of operations. The first line contains a single integer n ( 2 <= n <= 3 cdot 10^5 ) -- the length of the permutation. The second line contains n integers p_1, p_2, ldots, p_n ( 1 <= p_i <= n , the p_i are distinct) -- the permutation before performing the operations. Output your operations in the following format. The first line should contain an integer k ( 0 <= k <= 10^6 ) -- the number of operations. The next k lines represent the k operations in order. Each of these k lines should contain two integers l and r ( 1 <= q l < r <= q n , r-l+1 must be even) -- the corresponding operation consists in choosing the subarray [l, r] and swapping its elements according to the problem statement. After all the operations, a_i = i must be true for each i ( 1 <= q i <= q n ). In the first test: In the second test, the permutation is already sorted, so you do not need to perform any operation. '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
238607786 |
ksun48 |
H |
Dec. 23, 2023, 10:27 p.m. |
OK |
GNU C++17 |
TESTS |
40 |
1668 |
46182400 |
|
|
238600560 |
icecuber |
H |
Dec. 23, 2023, 8:02 p.m. |
OK |
GNU C++17 (64) |
TESTS |
40 |
343 |
30720000 |
|
|
238604446 |
Benq |
H |
Dec. 23, 2023, 9:07 p.m. |
OK |
GNU C++17 (64) |
TESTS |
40 |
343 |
30822400 |
|
|
238610730 |
Benq |
H |
Dec. 24, 2023, 12:21 a.m. |
OK |
GNU C++17 (64) |
TESTS |
40 |
1325 |
47513600 |
|
|
238615730 |
Sparkle_Twilight |
H |
Dec. 24, 2023, 2:58 a.m. |
OK |
GNU C++17 (64) |
TESTS |
40 |
1465 |
47513600 |
|
|
238616755 |
nguyenquocthinhhung |
H |
Dec. 24, 2023, 3:22 a.m. |
OK |
GNU C++20 (64) |
TESTS |
40 |
295 |
30208000 |
|
|
238606230 |
chappy1 |
H |
Dec. 23, 2023, 9:45 p.m. |
OK |
GNU C++20 (64) |
TESTS |
40 |
296 |
30208000 |
|
|
238589602 |
jiangly |
H |
Dec. 23, 2023, 6:11 p.m. |
OK |
GNU C++20 (64) |
TESTS |
40 |
311 |
30208000 |
|
|
238580264 |
maroonrk |
H |
Dec. 23, 2023, 5:09 p.m. |
OK |
GNU C++20 (64) |
TESTS |
40 |
358 |
68300800 |
|
|
238597182 |
ManojkumarPatanik |
H |
Dec. 23, 2023, 7:16 p.m. |
OK |
GNU C++20 (64) |
TESTS |
40 |
452 |
30208000 |
|
|
remove filters
Back to search problems