Codeforces Round 1052 (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
2146 Codeforces Round 1052 (Div. 2) FINISHED False 8100 17940323 Sept. 21, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 4004 ) D2 Max Sum OR (Hard Version) PROGRAMMING bitmasks constructive algorithms divide and conquer greedy

This is the hard version of the problem. The difference between the versions is that in this version, (0\leq l\leq r<2^{30}). You can hack only if you solved all versions of this problem. You are given two integers (l) and (r) ((l\le r)). Let (n = r - l + 1). We will create two arrays (a) and (b), both consisting of (n) integers. Initially, both (a) and (b) are equal to (l, l+1, \ldots, r). You have to reorder the array (a) arbitrarily to maximize the following value: ()\sum_{i=1}^n \left (a_i\;|\;b_i \right ).() Here, (|) denotes the bitwise OR operation . You also need to construct a possible way to reorder the array (a). 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 only line of each test case contains two integers (l) and (r) ((0\leq l \leq r<2^{30})) — the minimum and maximum elements in (a). Let (n = r - l + 1). It is guaranteed that the sum of (n) over all test cases does not exceed (2\cdot 10^5). For each test case, print a single integer in the first line of output — the maximum value of (\sum\limits_{i=1}^n \left (a_i\;|\;b_i \right )). Then, print (n) distinct integers (a_1, a_2, \ldots,a_n) in the second line — the array (a) after reordering. If there are multiple answers, you may print any of them. In the first test case, the reordered array (a) is (3,2,1,0). The value of the expression is ((3\;|\;0)+(2\;|\;1)+(1\;|\;2)+(0\;|\;3)=3+3+3+3=12). It can be proved that this is the maximum possible value of the expression. In the second test case, the reordered array (a) is (7,8,5,4,3,2,9,0,1,6). The value of the expression is (90). It can be proved that this is the maximum possible value of the expression. In the third test case, it can be proved that (240) is the maximum possible value

Tutorials

Codeforces Round 1052 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
339784959 11Hemeda D2 Sept. 21, 2025, 4:49 p.m. OK C# 13 TESTS 22 374 71168000
339816041 hanlei35 D2 Sept. 22, 2025, 1:53 a.m. OK C++17 (GCC 7-32) TESTS 22 77 0
339782507 namaay D2 Sept. 21, 2025, 4:44 p.m. OK C++17 (GCC 7-32) TESTS 22 77 102400
339781944 Saniok822 D2 Sept. 21, 2025, 4:42 p.m. OK C++17 (GCC 7-32) TESTS 22 77 102400
339815134 dustdream D2 Sept. 22, 2025, 1:38 a.m. OK C++17 (GCC 7-32) TESTS 22 78 0
339811895 JhdFarrell D2 Sept. 22, 2025, 12:10 a.m. OK C++17 (GCC 7-32) TESTS 22 78 0
339773026 mon_de2738 D2 Sept. 21, 2025, 4:17 p.m. OK C++17 (GCC 7-32) TESTS 22 78 819200
339802228 nvclon D2 Sept. 21, 2025, 7:51 p.m. OK C++17 (GCC 7-32) TESTS 22 92 0
339783868 hanlei35 D2 Sept. 21, 2025, 4:47 p.m. OK C++17 (GCC 7-32) TESTS 22 92 0
339822144 shy_paper D2 Sept. 22, 2025, 3:16 a.m. OK C++17 (GCC 7-32) TESTS 22 93 0
339815982 ggez09813 D2 Sept. 22, 2025, 1:52 a.m. OK C++17 (GCC 7-32) TESTS 22 93 0
339832971 kulovemi D2 Sept. 22, 2025, 5:39 a.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339821889 blackrabbit-zmk D2 Sept. 22, 2025, 3:12 a.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339821022 Redial D2 Sept. 22, 2025, 2:59 a.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339819161 FlowerandYou D2 Sept. 22, 2025, 2:35 a.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339816808 SeeItAgain D2 Sept. 22, 2025, 2:04 a.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339816257 ConvexHulllllll D2 Sept. 22, 2025, 1:57 a.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339814266 Blazagon D2 Sept. 22, 2025, 1:20 a.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339814006 Wu_Xin_45 D2 Sept. 22, 2025, 1:14 a.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339812960 AshrafSustS19 D2 Sept. 22, 2025, 12:43 a.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339802663 Ayham_Dabah D2 Sept. 21, 2025, 7:58 p.m. OK C++20 (GCC 13-64) TESTS 22 62 0
339834054 MaxDYF D2 Sept. 22, 2025, 5:51 a.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339827896 Kita3 D2 Sept. 22, 2025, 4:39 a.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339826173 L2ngg D2 Sept. 22, 2025, 4:14 a.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339820863 wrldplan D2 Sept. 22, 2025, 2:57 a.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339818450 momoforce D2 Sept. 22, 2025, 2:24 a.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339818047 123m456jx D2 Sept. 22, 2025, 2:19 a.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339812408 emoreira D2 Sept. 22, 2025, 12:26 a.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339811694 WTXwang D2 Sept. 22, 2025, 12:02 a.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339797860 dimastrakhal D2 Sept. 21, 2025, 6:54 p.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339796464 sachin_gupta21 D2 Sept. 21, 2025, 6:37 p.m. OK C++23 (GCC 14-64, msys2) TESTS 22 62 0
339783926 pengin_2000 D2 Sept. 21, 2025, 4:48 p.m. OK GNU C11 TESTS 22 155 4915200
339794140 zap4eg D2 Sept. 21, 2025, 6:12 p.m. OK Go TESTS 22 312 19660800
339784627 kkumar-gcc D2 Sept. 21, 2025, 4:49 p.m. OK Go TESTS 22 327 31129600
339795509 DreamyDusk D2 Sept. 21, 2025, 6:27 p.m. OK Java 21 TESTS 22 328 1740800
339777447 AlgoMaster2024 D2 Sept. 21, 2025, 4:29 p.m. OK Java 21 TESTS 22 358 2355200
339776140 anshwww D2 Sept. 21, 2025, 4:25 p.m. OK Java 21 TESTS 22 374 2764800
339775330 n384470 D2 Sept. 21, 2025, 4:23 p.m. OK Java 21 TESTS 22 437 25600000
339777788 hs1663531 D2 Sept. 21, 2025, 4:30 p.m. OK Java 21 TESTS 22 452 26009600
339782515 pscrwh D2 Sept. 21, 2025, 4:44 p.m. OK Java 21 TESTS 22 608 1536000
339773881 D_Cod3r D2 Sept. 21, 2025, 4:19 p.m. OK Java 21 TESTS 22 656 1331200
339783950 Animesh1008 D2 Sept. 21, 2025, 4:48 p.m. OK Java 21 TESTS 22 686 10137600
339781817 ataral427 D2 Sept. 21, 2025, 4:42 p.m. OK Java 21 TESTS 22 843 1228800
339783280 bansalram5903 D2 Sept. 21, 2025, 4:46 p.m. OK Java 21 TESTS 22 1280 60620800
339774515 bhawnapannu2701 D2 Sept. 21, 2025, 4:21 p.m. OK Java 8 TESTS 22 187 9318400
339789704 amre_8800 D2 Sept. 21, 2025, 5:36 p.m. OK Java 8 TESTS 22 546 0
339775522 mohitsharmakv05 D2 Sept. 21, 2025, 4:24 p.m. OK Node.js TESTS 22 749 51097600
339774447 vlk0 D2 Sept. 21, 2025, 4:21 p.m. OK PyPy 3 TESTS 22 749 23756800
339777023 AL_Qiswa D2 Sept. 21, 2025, 4:28 p.m. OK PyPy 3 TESTS 22 1406 165376000
339805024 34z12000 D2 Sept. 21, 2025, 8:39 p.m. OK PyPy 3-64 TESTS 22 156 13414400
339777963 bcollet D2 Sept. 21, 2025, 4:30 p.m. OK PyPy 3-64 TESTS 22 171 15872000
339789531 sushmanth.dampur8780 D2 Sept. 21, 2025, 5:35 p.m. OK PyPy 3-64 TESTS 22 217 13414400
339797946 LMeyling D2 Sept. 21, 2025, 6:55 p.m. OK PyPy 3-64 TESTS 22 233 15155200
339781158 VioletVal D2 Sept. 21, 2025, 4:40 p.m. OK PyPy 3-64 TESTS 22 249 13824000
339779078 kamio-misuzu D2 Sept. 21, 2025, 4:34 p.m. OK PyPy 3-64 TESTS 22 249 16998400
339775604 ibraheemkureshi D2 Sept. 21, 2025, 4:24 p.m. OK PyPy 3-64 TESTS 22 249 18329600
339794132 Maruzensky D2 Sept. 21, 2025, 6:12 p.m. OK PyPy 3-64 TESTS 22 265 12288000
339781322 bkdn25.myhng_ D2 Sept. 21, 2025, 4:40 p.m. OK PyPy 3-64 TESTS 22 265 12288000
339773330 Ayis137 D2 Sept. 21, 2025, 4:18 p.m. OK PyPy 3-64 TESTS 22 265 13414400
339782686 tanishqsingh04 D2 Sept. 21, 2025, 4:44 p.m. OK Python 2 TESTS 22 1171 14336000
339775149 Jimanbanashi D2 Sept. 21, 2025, 4:23 p.m. OK Python 2 TESTS 22 1968 18227200
339770541 bj142152144 D2 Sept. 21, 2025, 4:10 p.m. OK Python 3 TESTS 22 390 61235200
339779746 RANDOM152 D2 Sept. 21, 2025, 4:35 p.m. OK Python 3 TESTS 22 671 25497600
339798846 catgirl D2 Sept. 21, 2025, 7:06 p.m. OK Python 3 TESTS 22 1421 11673600
339819007 niraj_kumar205 D2 Sept. 22, 2025, 2:33 a.m. OK Python 3 TESTS 22 1593 11673600
339779247 sbt214 D2 Sept. 21, 2025, 4:34 p.m. OK Python 3 TESTS 22 1952 13107200
339771194 QuantX D2 Sept. 21, 2025, 4:12 p.m. OK Rust 2024 TESTS 22 62 102400
339775326 WASDetchan D2 Sept. 21, 2025, 4:23 p.m. OK Rust 2024 TESTS 22 93 102400

remove filters

Back to search problems