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 |
|---|---|---|---|---|---|---|
| 700 | Codeforces Round 364 (Div. 1) | FINISHED | False | 7200 | 307200323 | July 22, 2016, 4:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 525 ) | D | Huffman Coding on Segment | PROGRAMMING | data structures greedy | 3000 |
Alice wants to send an important message to Bob. Message a = ( a 1 , ..., a n ) is a sequence of positive integers ( characters ). To compress the message Alice wants to use binary Huffman coding. We recall that binary Huffman code , or binary prefix code is a function f , that maps each letter that appears in the string to some binary string (that is, string consisting of characters ' 0 ' and ' 1 ' only) such that for each pair of different characters a i and a j string f ( a i ) is not a prefix of f ( a j ) (and vice versa). The result of the encoding of the message a 1 , a 2 , ..., a n is the concatenation of the encoding of each character, that is the string f ( a 1 ) f ( a 2 )... f ( a n ) . Huffman codes are very useful, as the compressed message can be easily and uniquely decompressed, if the function f is given. Code is usually chosen in order to minimize the total length of the compressed message, i.e. the length of the string f ( a 1 ) f ( a 2 )... f ( a n ) . Because of security issues Alice doesn't want to send the whole message. Instead, she picks some substrings of the message and wants to send them separately. For each of the given substrings a l i ... a r i she wants to know the minimum possible length of the Huffman coding. Help her solve this problem. The first line of the input contains the single integer n ( 1 ≤ n ≤ 100 000 ) — the length of the initial message. The second line contains n integers a 1 , a 2 , ..., a n ( 1 ≤ a i ≤ 100 000 ) — characters of the message. Next line contains the single integer q ( 1 ≤ q ≤ 100 000 ) — the number of queries. Then follow q lines with queries descriptions. The i -th of these lines contains two integers l i and r i ( 1 ≤ l i ≤ r i ≤ n ) — the position of the left and right ends of the i -th substring respectively. Positions are numbered from 1 . Substrings may overlap in any way. The same substring may appear in the input more than once. Print q lines. Each line should contain a single integer — |
| 46283 |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 19428304 | Swistakk | D | July 26, 2016, 6:54 p.m. | OK | D | TESTS | 48 | 2713 | 11264000 | 3000 | |
| 40984001 | ReaLNero1 | D | July 30, 2018, 7:08 p.m. | OK | GNU C++ | TESTS | 48 | 327 | 4198400 | 3000 | |
| 21335701 | Ajatar | D | Oct. 10, 2016, 10:37 a.m. | OK | GNU C++ | TESTS | 48 | 327 | 6246400 | 3000 | |
| 20282912 | white_caster | D | Aug. 30, 2016, 2:50 p.m. | OK | GNU C++ | TESTS | 48 | 358 | 2662400 | 3000 | |
| 21348637 | zhanglexing | D | Oct. 11, 2016, 12:09 a.m. | OK | GNU C++ | TESTS | 48 | 358 | 4710400 | 3000 | |
| 21309304 | returnzoo | D | Oct. 9, 2016, 4:48 a.m. | OK | GNU C++ | TESTS | 48 | 436 | 5939200 | 3000 | |
| 23172696 | ZaakDov | D | Dec. 20, 2016, 8:25 a.m. | OK | GNU C++ | TESTS | 48 | 592 | 7475200 | 3000 | |
| 38458328 | vjudge3 | D | May 20, 2018, 11:48 a.m. | OK | GNU C++ | TESTS | 48 | 639 | 4403200 | 3000 | |
| 23172724 | ZaakDov | D | Dec. 20, 2016, 8:27 a.m. | OK | GNU C++ | TESTS | 48 | 763 | 7475200 | 3000 | |
| 19518275 | Vlad_kv | D | July 30, 2016, 1:29 p.m. | OK | GNU C++ | TESTS | 48 | 779 | 6963200 | 3000 | |
| 19775797 | Philipsweng | D | Aug. 11, 2016, 2:51 a.m. | OK | GNU C++ | TESTS | 48 | 904 | 8089600 | 3000 | |
| 21329687 | HeZiying | D | Oct. 10, 2016, 3:36 a.m. | OK | GNU C++11 | TESTS | 48 | 327 | 6246400 | 3000 | |
| 21331035 | HeZiying | D | Oct. 10, 2016, 6:04 a.m. | OK | GNU C++11 | TESTS | 48 | 343 | 6246400 | 3000 | |
| 21331073 | HeZiying | D | Oct. 10, 2016, 6:06 a.m. | OK | GNU C++11 | TESTS | 48 | 405 | 6348800 | 3000 | |
| 19354009 | johnchen902 | D | July 23, 2016, 3:01 a.m. | OK | GNU C++11 | TESTS | 48 | 498 | 3379200 | 3000 | |
| 56466729 | KMAASZRAA | D | July 3, 2019, 9:14 a.m. | OK | GNU C++11 | TESTS | 48 | 514 | 3174400 | 3000 | |
| 19405543 | Irisviel_von_Einzber | D | July 25, 2016, 2:31 p.m. | OK | GNU C++11 | TESTS | 48 | 654 | 4812800 | 3000 | |
| 24728949 | King_George | D | Feb. 17, 2017, 12:50 a.m. | OK | GNU C++11 | TESTS | 48 | 701 | 7270400 | 3000 | |
| 19851694 | codestrength | D | Aug. 13, 2016, 2:01 p.m. | OK | GNU C++11 | TESTS | 48 | 702 | 6246400 | 3000 | |
| 21409802 | -XraY- | D | Oct. 13, 2016, 6:10 p.m. | OK | GNU C++11 | TESTS | 48 | 733 | 9932800 | 3000 | |
| 20343806 | krijgertje | D | Sept. 2, 2016, 3:36 p.m. | OK | GNU C++11 | TESTS | 48 | 763 | 5632000 | 3000 | |
| 27050446 | ko_osaga | D | May 12, 2017, 9:04 a.m. | OK | GNU C++14 | TESTS | 48 | 889 | 3379200 | 3000 | |
| 69702175 | Scut82 | D | Jan. 29, 2020, 1:39 a.m. | OK | GNU C++14 | TESTS | 48 | 1014 | 3174400 | 3000 | |
| 69702132 | Scut82 | D | Jan. 29, 2020, 1:36 a.m. | OK | GNU C++14 | TESTS | 48 | 1247 | 3174400 | 3000 | |
| 21348783 | Oktavia | D | Oct. 11, 2016, 12:32 a.m. | OK | GNU C++14 | TESTS | 48 | 1263 | 7884800 | 3000 | |
| 31180628 | FallDream | D | Oct. 10, 2017, 4:04 a.m. | OK | GNU C++14 | TESTS | 48 | 1512 | 73625600 | 3000 | |
| 29495963 | whzzt | D | Aug. 16, 2017, 4:30 a.m. | OK | GNU C++14 | TESTS | 48 | 1528 | 5324800 | 3000 | |
| 31180534 | ditoly | D | Oct. 10, 2017, 3:51 a.m. | OK | GNU C++14 | TESTS | 48 | 1543 | 5222400 | 3000 | |
| 26876018 | RNS3 | D | May 5, 2017, 8:18 a.m. | OK | GNU C++14 | TESTS | 48 | 1590 | 5836800 | 3000 | |
| 26045236 | MLVXD | D | April 1, 2017, 6:55 a.m. | OK | GNU C++14 | TESTS | 48 | 1606 | 5939200 | 3000 | |
| 21328835 | Steven_Chen | D | Oct. 10, 2016, 1:16 a.m. | OK | GNU C++14 | TESTS | 48 | 1638 | 13926400 | 3000 | |
| 52437114 | Shayan.P | D | April 7, 2019, 4:22 a.m. | OK | GNU C++17 | TESTS | 48 | 732 | 3993600 | 3000 | |
| 65023973 | tEMMIE.w. | D | Nov. 15, 2019, 6:43 a.m. | OK | GNU C++17 | TESTS | 48 | 1326 | 4915200 | 3000 | |
| 39659642 | gepardo | D | June 25, 2018, 8:28 p.m. | OK | GNU C++17 | TESTS | 48 | 1341 | 4300800 | 3000 | |
| 39659680 | gepardo | D | June 25, 2018, 8:30 p.m. | OK | GNU C++17 | TESTS | 48 | 1357 | 4300800 | 3000 | |
| 39658713 | gepardo | D | June 25, 2018, 7:23 p.m. | OK | GNU C++17 | TESTS | 48 | 1497 | 3276800 | 3000 | |
| 39658698 | gepardo | D | June 25, 2018, 7:22 p.m. | OK | GNU C++17 | TESTS | 48 | 1497 | 3276800 | 3000 | |
| 57559124 | Benq | D | July 22, 2019, 10:18 p.m. | OK | GNU C++17 | TESTS | 48 | 1512 | 4812800 | 3000 | |
| 50583264 | CMXRYNP | D | Feb. 28, 2019, 12:10 a.m. | OK | GNU C++17 | TESTS | 48 | 1559 | 14950400 | 3000 | |
| 50583419 | CMXRYNP | D | Feb. 28, 2019, 12:22 a.m. | OK | GNU C++17 | TESTS | 48 | 1590 | 14950400 | 3000 | |
| 50583409 | CMXRYNP | D | Feb. 28, 2019, 12:22 a.m. | OK | GNU C++17 | TESTS | 48 | 1622 | 14950400 | 3000 | |
| 19934139 | IgorKoval | D | Aug. 17, 2016, 6:56 p.m. | OK | Java 8 | TESTS | 48 | 1248 | 29081600 | 3000 | |
| 26050910 | tiboy | D | April 1, 2017, 11:07 a.m. | OK | Java 8 | TESTS | 48 | 1279 | 30208000 | 3000 | |
| 26036871 | vinceftw | D | March 31, 2017, 9:36 p.m. | OK | Java 8 | TESTS | 48 | 1762 | 30208000 | 3000 | |
| 26036808 | vinceftw | D | March 31, 2017, 9:33 p.m. | OK | Java 8 | TESTS | 48 | 1777 | 30208000 | 3000 | |
| 25975963 | Gan656 | D | March 31, 2017, 10:39 a.m. | OK | Java 8 | TESTS | 48 | 1777 | 30208000 | 3000 | |
| 25873668 | ethanray19 | D | March 28, 2017, 12:46 p.m. | OK | Java 8 | TESTS | 48 | 1777 | 30208000 | 3000 | |
| 26054340 | Yuchipashe | D | April 1, 2017, 1:14 p.m. | OK | Java 8 | TESTS | 48 | 1778 | 30208000 | 3000 | |
| 25953506 | jannellyjelly | D | March 30, 2017, 1:17 p.m. | OK | Java 8 | TESTS | 48 | 1793 | 29900800 | 3000 | |
| 25950215 | thessaquijote | D | March 30, 2017, 11:29 a.m. | OK | Java 8 | TESTS | 48 | 1793 | 30003200 | 3000 | |
| 26045950 | palacioje | D | April 1, 2017, 7:31 a.m. | OK | Java 8 | TESTS | 48 | 1793 | 30208000 | 3000 | |
| 19671664 | Los_Angelos_Laycurse | D | Aug. 6, 2016, 2:29 p.m. | OK | MS C++ | TESTS | 48 | 904 | 6041600 | 3000 |
Back to search problems