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 |
|---|---|---|---|---|---|---|
| 2164 | Codeforces Global Round 30 (Div. 1 + Div. 2) | FINISHED | False | 10800 | 13965923 | Nov. 6, 2025, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 418 ) | F2 | Chain Prefix Rank (Hard Version) | PROGRAMMING | combinatorics data structures dp math |
This is the hard version of the problem. The difference between the versions is that in this version, (n \le 5 \cdot 10^5). You can hack only if you solved all versions of this problem. Given a tree (T) with (n) vertices rooted at (1) and a sequence (a) of length (n), count the number of permutations(^{\text{∗}}) (p) of length (n) that satisfy the following condition: For all (1 \le u \le n), there are exactly (a_u) vertices (v) such that (v) is an ancestor of (u) in (T) and (p_v < p_u). Output the answer modulo (998\,244\,353). Input data is selected in such way, such that it's guaranteed that at least one valid permutation exists. (^{\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). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 5000)). The description of the test cases follows. The first line of each test case contains an integer (n) ((2 \le n \le 5 \cdot 10^5)) — the number of vertices. The second line of each test case contains (n-1) integers (fa_2,fa_3,\ldots,fa_n) ((1 \le fa_i < i))— (fa_i) is the parent of (i) on (T). The third line of each test case contains (n) integers (a_1,a_2,\ldots,a_n) ((0 \le a_i < n)). It is guaranteed that the sum of (n) over all test cases does not exceed (5 \cdot 10^5). Input data is selected in such way, such that it's guaranteed that at least one valid permutation exists. For each test case, output one integer — the number of permutations modulo (998\,244\,353). Visualizer link In the first test case, the only permutation whic |
| Codeforces Global Round 30 Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 347822199 | p6pou | F2 | Nov. 7, 2025, 4:10 a.m. | OK | C++17 (GCC 7-32) | TESTS | 27 | 749 | 54169600 | ||
| 347822253 | p6pou | F2 | Nov. 7, 2025, 4:10 a.m. | OK | C++17 (GCC 7-32) | TESTS | 27 | 796 | 54169600 | ||
| 347782281 | wthdouwant | F2 | Nov. 6, 2025, 6:30 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 921 | 64716800 | ||
| 347763480 | HugeWide | F2 | Nov. 6, 2025, 4:52 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 1546 | 69324800 | ||
| 347771952 | TadijaSebez | F2 | Nov. 6, 2025, 5:18 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 1562 | 750080000 | ||
| 347766827 | as_dfsdf | F2 | Nov. 6, 2025, 5:02 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 2046 | 260198400 | ||
| 347786897 | qwef_ | F2 | Nov. 6, 2025, 7:09 p.m. | OK | C++17 (GCC 7-32) | TESTS | 23 | 2327 | 300339200 | ||
| 347826731 | Famid_1645 | F2 | Nov. 7, 2025, 5:11 a.m. | OK | C++17 (GCC 7-32) | TESTS | 27 | 2984 | 220467200 | ||
| 347822208 | masonpop | F2 | Nov. 7, 2025, 4:10 a.m. | OK | C++17 (GCC 7-32) | TESTS | 27 | 2984 | 220467200 | ||
| 347770278 | Rainbow_qwq | F2 | Nov. 6, 2025, 5:13 p.m. | OK | C++17 (GCC 7-32) | TESTS | 22 | 3546 | 349388800 | ||
| 347787105 | maxplus | F2 | Nov. 6, 2025, 7:11 p.m. | OK | C++20 (GCC 13-64) | TESTS | 23 | 687 | 72704000 | ||
| 347786626 | maxplus | F2 | Nov. 6, 2025, 7:07 p.m. | OK | C++20 (GCC 13-64) | TESTS | 23 | 718 | 72704000 | ||
| 347786325 | maxplus | F2 | Nov. 6, 2025, 7:04 p.m. | OK | C++20 (GCC 13-64) | TESTS | 23 | 749 | 78028800 | ||
| 347786215 | maxplus | F2 | Nov. 6, 2025, 7:03 p.m. | OK | C++20 (GCC 13-64) | TESTS | 23 | 780 | 83353600 | ||
| 347786819 | maxplus | F2 | Nov. 6, 2025, 7:09 p.m. | OK | C++20 (GCC 13-64) | TESTS | 23 | 796 | 72704000 | ||
| 347775066 | maxplus | F2 | Nov. 6, 2025, 5:28 p.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 811 | 129638400 | ||
| 347784435 | maxplus | F2 | Nov. 6, 2025, 6:47 p.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 1046 | 83353600 | ||
| 347785673 | LMydd0225 | F2 | Nov. 6, 2025, 6:58 p.m. | OK | C++20 (GCC 13-64) | TESTS | 23 | 1046 | 535654400 | ||
| 347767709 | EasonTAO | F2 | Nov. 6, 2025, 5:04 p.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 1062 | 221286400 | ||
| 347769332 | VladProg | F2 | Nov. 6, 2025, 5:10 p.m. | OK | C++20 (GCC 13-64) | TESTS | 22 | 1109 | 117043200 | ||
| 347798700 | hungchi17 | F2 | Nov. 6, 2025, 9:22 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 27 | 671 | 93388800 | ||
| 347795952 | allvik66 | F2 | Nov. 6, 2025, 8:44 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 27 | 843 | 117043200 | ||
| 347764337 | Petr | F2 | Nov. 6, 2025, 4:54 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 906 | 29184000 | ||
| 347820824 | lzm0107 | F2 | Nov. 7, 2025, 3:52 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 27 | 952 | 111411200 | ||
| 347769467 | Mangooste | F2 | Nov. 6, 2025, 5:10 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 1077 | 109363200 | ||
| 347769101 | carcinisation | F2 | Nov. 6, 2025, 5:09 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 1093 | 99737600 | ||
| 347783560 | jackuchan04 | F2 | Nov. 6, 2025, 6:40 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 1109 | 103424000 | ||
| 347782283 | namespace_std | F2 | Nov. 6, 2025, 6:30 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 1171 | 169676800 | ||
| 347801219 | Adam_GS | F2 | Nov. 6, 2025, 10:05 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 27 | 1187 | 122982400 | ||
| 347766815 | MYFJCHX | F2 | Nov. 6, 2025, 5:02 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 22 | 1281 | 113049600 | ||
| 347772982 | Sugar_fan | F2 | Nov. 6, 2025, 5:21 p.m. | OK | Rust 2024 | TESTS | 22 | 983 | 151859200 |
Back to search problems