Task: | Bathhouse |
Sender: | aalto2024d_004 |
Submission time: | 2024-09-25 16:49:46 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | ACCEPTED | 0.00 s | details |
#18 | ACCEPTED | 0.00 s | details |
#19 | ACCEPTED | 0.00 s | details |
#20 | ACCEPTED | 0.00 s | details |
#21 | ACCEPTED | 0.00 s | details |
#22 | ACCEPTED | 0.00 s | details |
#23 | ACCEPTED | 0.00 s | details |
#24 | ACCEPTED | 0.00 s | details |
#25 | ACCEPTED | 0.00 s | details |
#26 | ACCEPTED | 0.00 s | details |
#27 | ACCEPTED | 0.00 s | details |
#28 | ACCEPTED | 0.00 s | details |
#29 | ACCEPTED | 0.00 s | details |
#30 | ACCEPTED | 0.00 s | details |
#31 | ACCEPTED | 0.00 s | details |
#32 | ACCEPTED | 0.00 s | details |
#33 | ACCEPTED | 0.00 s | details |
#34 | ACCEPTED | 0.00 s | details |
#35 | ACCEPTED | 0.00 s | details |
#36 | ACCEPTED | 0.00 s | details |
#37 | ACCEPTED | 0.00 s | details |
#38 | ACCEPTED | 0.00 s | details |
#39 | ACCEPTED | 0.00 s | details |
#40 | ACCEPTED | 0.00 s | details |
#41 | ACCEPTED | 0.00 s | details |
#42 | ACCEPTED | 0.00 s | details |
#43 | ACCEPTED | 0.00 s | details |
#44 | ACCEPTED | 0.00 s | details |
#45 | ACCEPTED | 0.00 s | details |
#46 | ACCEPTED | 0.00 s | details |
#47 | ACCEPTED | 0.00 s | details |
#48 | ACCEPTED | 0.00 s | details |
#49 | ACCEPTED | 0.00 s | details |
#50 | ACCEPTED | 0.00 s | details |
#51 | ACCEPTED | 0.01 s | details |
#52 | ACCEPTED | 0.01 s | details |
#53 | ACCEPTED | 0.01 s | details |
#54 | ACCEPTED | 0.01 s | details |
#55 | ACCEPTED | 0.01 s | details |
#56 | ACCEPTED | 0.01 s | details |
#57 | ACCEPTED | 0.01 s | details |
#58 | ACCEPTED | 0.01 s | details |
#59 | ACCEPTED | 0.01 s | details |
#60 | ACCEPTED | 0.01 s | details |
#61 | ACCEPTED | 0.10 s | details |
#62 | ACCEPTED | 0.10 s | details |
#63 | ACCEPTED | 0.11 s | details |
#64 | ACCEPTED | 0.11 s | details |
#65 | ACCEPTED | 0.10 s | details |
#66 | ACCEPTED | 0.10 s | details |
#67 | ACCEPTED | 0.10 s | details |
#68 | ACCEPTED | 0.10 s | details |
#69 | ACCEPTED | 0.10 s | details |
#70 | ACCEPTED | 0.10 s | details |
Code
#include <bits/stdc++.h> using namespace std; int main() { int N, Q; cin >> N >> Q; int *P = new int[N+1]; for (int i = 1; i <= N; i++) cin >> P[i]; long long max_A = 0; long long *A = new long long[Q]; for (int i = 0; i < Q; i++) { cin >> A[i]; max_A = max(A[i], max_A); } vector<int> seconds_to_case; int current = 1; int second = 0; long long cycle_start = -1; long long cycle_length = -1; unordered_map<int, int> visited; while (second <= max_A) { if (!visited.count(current)) { visited[current] = second; seconds_to_case.push_back(current); current = P[current]; } else { cycle_start = visited[current]; cycle_length = second - cycle_start; break; } second++; } // second < cycle_start or // second = cycle_start + x * cycle_length + y for (int i = 0; i < Q; i++) { if (A[i] < cycle_start) cout << seconds_to_case[A[i]] << " "; else { long long z = A[i] - cycle_start; long long x = z / cycle_length; long long y = z - x * cycle_length; cout << seconds_to_case[cycle_start + y] << " "; } } cout << endl; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 3 1 3 1 2 |
correct output |
---|
1 1 1 |
user output |
---|
1 1 1 |
Test 2
Verdict: ACCEPTED
input |
---|
2 2 1 2 5 1 |
correct output |
---|
1 1 |
user output |
---|
1 1 |
Test 3
Verdict: ACCEPTED
input |
---|
2 3 1 2 5 1 4 |
correct output |
---|
1 1 1 |
user output |
---|
1 1 1 |
Test 4
Verdict: ACCEPTED
input |
---|
2 3 1 2 5 1 4 |
correct output |
---|
1 1 1 |
user output |
---|
1 1 1 |
Test 5
Verdict: ACCEPTED
input |
---|
3 3 2 1 1 7 2 7 |
correct output |
---|
2 1 2 |
user output |
---|
2 1 2 |
Test 6
Verdict: ACCEPTED
input |
---|
3 8 3 1 1 7 2 7 9 0 4 2 0 |
correct output |
---|
3 1 3 3 1 1 1 1 |
user output |
---|
3 1 3 3 1 1 1 1 |
Test 7
Verdict: ACCEPTED
input |
---|
3 5 1 3 2 7 2 7 9 0 |
correct output |
---|
1 1 1 1 1 |
user output |
---|
1 1 1 1 1 |
Test 8
Verdict: ACCEPTED
input |
---|
4 4 2 3 3 1 10 3 9 12 |
correct output |
---|
3 3 3 3 |
user output |
---|
3 3 3 3 |
Test 9
Verdict: ACCEPTED
input |
---|
4 7 1 3 3 3 10 3 9 12 0 5 3 |
correct output |
---|
1 1 1 1 1 1 1 |
user output |
---|
1 1 1 1 1 1 1 |
Test 10
Verdict: ACCEPTED
input |
---|
4 11 1 4 1 2 10 3 9 12 0 5 3 0 6 4 3 |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 |
Test 11
Verdict: ACCEPTED
input |
---|
5 11 3 3 4 3 3 12 4 11 15 0 6 4 0 8 5 4 |
correct output |
---|
4 4 3 3 1 4 4 1 4 3 4 |
user output |
---|
4 4 3 3 1 4 4 1 4 3 4 |
Test 12
Verdict: ACCEPTED
input |
---|
5 9 1 1 4 3 2 12 4 11 15 0 6 4 0 8 |
correct output |
---|
1 1 1 1 1 1 1 1 1 |
user output |
---|
1 1 1 1 1 1 1 1 1 |
Test 13
Verdict: ACCEPTED
input |
---|
5 9 2 3 3 2 3 12 4 11 15 0 6 4 0 8 |
correct output |
---|
3 3 3 3 1 3 3 1 3 |
user output |
---|
3 3 3 3 1 3 3 1 3 |
Test 14
Verdict: ACCEPTED
input |
---|
5 11 1 1 5 2 5 12 4 11 15 0 6 4 0 8 5 4 |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 |
Test 15
Verdict: ACCEPTED
input |
---|
5 15 5 2 4 3 5 12 4 11 15 0 6 4 0 8 5 4 8 2 8... |
correct output |
---|
5 5 5 5 1 5 5 1 5 5 5 5 5 5 5 |
user output |
---|
5 5 5 5 1 5 5 1 5 5 5 5 5 5 5 |
Test 16
Verdict: ACCEPTED
input |
---|
5 7 3 4 5 4 5 12 4 11 15 0 6 4 |
correct output |
---|
5 5 5 5 1 5 5 |
user output |
---|
5 5 5 5 1 5 5 |
Test 17
Verdict: ACCEPTED
input |
---|
5 14 5 1 3 2 4 12 4 11 15 0 6 4 0 8 5 4 8 2 8... |
correct output |
---|
1 1 2 2 1 4 1 1 1 5 1 1 4 1 |
user output |
---|
1 1 2 2 1 4 1 1 1 5 1 1 4 1 |
Test 18
Verdict: ACCEPTED
input |
---|
5 5 5 3 4 4 3 12 4 11 15 0 |
correct output |
---|
4 4 4 4 1 |
user output |
---|
4 4 4 4 1 |
Test 19
Verdict: ACCEPTED
input |
---|
5 14 3 5 2 4 3 12 4 11 15 0 6 4 0 8 5 4 8 2 8... |
correct output |
---|
5 3 2 5 1 5 3 1 2 2 3 2 2 2 |
user output |
---|
5 3 2 5 1 5 3 1 2 2 3 2 2 2 |
Test 20
Verdict: ACCEPTED
input |
---|
5 5 1 1 4 3 2 12 4 11 15 0 |
correct output |
---|
1 1 1 1 1 |
user output |
---|
1 1 1 1 1 |
Test 21
Verdict: ACCEPTED
input |
---|
10 21 4 8 3 3 4 2 7 10 3 1 24 7 22 29 0 12 7 0 16 10 8 17... |
correct output |
---|
3 3 3 3 1 3 3 1 3 3 3 3 3 3 3 ... |
user output |
---|
3 3 3 3 1 3 3 1 3 3 3 3 3 3 3 ... |
Test 22
Verdict: ACCEPTED
input |
---|
10 18 3 4 3 4 5 1 4 7 2 9 24 7 22 29 0 12 7 0 16 10 8 17... |
correct output |
---|
3 3 3 3 1 3 3 1 3 3 3 3 3 3 3 ... |
user output |
---|
3 3 3 3 1 3 3 1 3 3 3 3 3 3 3 ... |
Test 23
Verdict: ACCEPTED
input |
---|
10 19 4 1 2 4 5 10 7 6 9 3 24 7 22 29 0 12 7 0 16 10 8 17... |
correct output |
---|
4 4 4 4 1 4 4 1 4 4 4 4 4 4 4 ... |
user output |
---|
4 4 4 4 1 4 4 1 4 4 4 4 4 4 4 ... |
Test 24
Verdict: ACCEPTED
input |
---|
10 21 3 1 1 2 1 1 3 4 5 8 24 7 22 29 0 12 7 0 16 10 8 17... |
correct output |
---|
1 3 1 3 1 1 3 1 1 1 1 3 1 1 1 ... |
user output |
---|
1 3 1 3 1 1 3 1 1 1 1 3 1 1 1 ... |
Test 25
Verdict: ACCEPTED
input |
---|
10 30 3 1 7 2 10 6 7 7 7 2 24 7 22 29 0 12 7 0 16 10 8 17... |
correct output |
---|
7 7 7 7 1 7 7 1 7 7 7 7 7 7 7 ... |
user output |
---|
7 7 7 7 1 7 7 1 7 7 7 7 7 7 7 ... |
Test 26
Verdict: ACCEPTED
input |
---|
10 14 9 3 5 9 9 4 1 7 8 4 24 7 22 29 0 12 7 0 16 10 8 17... |
correct output |
---|
1 7 8 9 1 1 7 1 1 8 1 9 1 1 |
user output |
---|
1 7 8 9 1 1 7 1 1 8 1 9 1 1 |
Test 27
Verdict: ACCEPTED
input |
---|
10 28 9 4 1 4 2 10 3 7 6 8 24 7 22 29 0 12 7 0 16 10 8 17... |
correct output |
---|
10 1 9 9 1 7 1 1 6 10 9 10 8 6... |
user output |
---|
10 1 9 9 1 7 1 1 6 10 9 10 8 6... |
Test 28
Verdict: ACCEPTED
input |
---|
10 11 1 5 5 7 1 3 6 2 9 5 24 7 22 29 0 12 7 0 16 10 8 |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 |
Test 29
Verdict: ACCEPTED
input |
---|
10 28 5 6 9 10 9 5 7 2 4 9 24 7 22 29 0 12 7 0 16 10 8 17... |
correct output |
---|
4 10 10 9 1 4 10 1 10 10 9 9 1... |
user output |
---|
4 10 10 9 1 4 10 1 10 10 9 9 1... |
Test 30
Verdict: ACCEPTED
input |
---|
10 10 10 4 1 8 4 5 1 7 2 9 24 7 22 29 0 12 7 0 16 10 |
correct output |
---|
2 1 10 10 1 8 1 1 9 2 |
user output |
---|
2 1 10 10 1 8 1 1 9 2 |
Test 31
Verdict: ACCEPTED
input |
---|
100 210 14 74 92 58 7 98 86 25 60 70 5... |
correct output |
---|
42 13 50 42 26 26 26 50 94 13 ... |
user output |
---|
42 13 50 42 26 26 26 50 94 13 ... Truncated |
Test 32
Verdict: ACCEPTED
input |
---|
100 183 53 97 95 2 54 17 95 63 2 91 6 ... |
correct output |
---|
58 95 97 95 58 97 33 58 30 30 ... |
user output |
---|
58 95 97 95 58 97 33 58 30 30 ... Truncated |
Test 33
Verdict: ACCEPTED
input |
---|
100 187 74 58 2 29 82 83 47 100 91 35 ... |
correct output |
---|
96 63 80 54 63 80 72 28 99 63 ... |
user output |
---|
96 63 80 54 63 80 72 28 99 63 ... Truncated |
Test 34
Verdict: ACCEPTED
input |
---|
100 210 26 63 66 33 58 41 21 46 19 8 7... |
correct output |
---|
38 47 27 28 75 47 75 8 55 8 75... |
user output |
---|
38 47 27 28 75 47 75 8 55 8 75... Truncated |
Test 35
Verdict: ACCEPTED
input |
---|
100 294 74 81 21 85 28 25 8 99 43 90 2... |
correct output |
---|
87 41 32 95 28 12 12 32 84 9 1... |
user output |
---|
87 41 32 95 28 12 12 32 84 9 1... Truncated |
Test 36
Verdict: ACCEPTED
input |
---|
100 144 99 85 10 97 5 58 26 92 95 97 6... |
correct output |
---|
41 25 90 59 46 90 70 46 48 60 ... |
user output |
---|
41 25 90 59 46 90 70 46 48 60 ... Truncated |
Test 37
Verdict: ACCEPTED
input |
---|
100 279 93 92 21 40 79 40 20 7 65 16 3... |
correct output |
---|
96 49 20 96 77 46 77 20 7 49 6... |
user output |
---|
96 49 20 96 77 46 77 20 7 49 6... Truncated |
Test 38
Verdict: ACCEPTED
input |
---|
100 115 33 75 25 88 30 21 6 11 28 70 4... |
correct output |
---|
85 84 84 85 84 84 84 84 85 84 ... |
user output |
---|
85 84 84 85 84 84 84 84 85 84 ... Truncated |
Test 39
Verdict: ACCEPTED
input |
---|
100 275 42 1 7 71 56 79 81 17 60 23 52... |
correct output |
---|
75 8 93 97 1 19 71 80 16 1 93 ... |
user output |
---|
75 8 93 97 1 19 71 80 16 1 93 ... Truncated |
Test 40
Verdict: ACCEPTED
input |
---|
100 102 76 86 4 54 65 98 12 3 65 23 99... |
correct output |
---|
19 14 67 19 45 56 56 67 45 14 ... |
user output |
---|
19 14 67 19 45 56 56 67 45 14 ... Truncated |
Test 41
Verdict: ACCEPTED
input |
---|
200 420 14 63 135 70 7 59 198 180 108 ... |
correct output |
---|
143 165 88 149 165 88 151 159 ... |
user output |
---|
143 165 88 149 165 88 151 159 ... Truncated |
Test 42
Verdict: ACCEPTED
input |
---|
200 367 92 55 151 199 107 153 113 22 1... |
correct output |
---|
55 2 175 111 64 175 191 64 187... |
user output |
---|
55 2 175 111 64 175 191 64 187... Truncated |
Test 43
Verdict: ACCEPTED
input |
---|
200 374 87 142 156 80 82 95 57 100 122... |
correct output |
---|
76 200 146 76 21 21 21 146 99 ... |
user output |
---|
76 200 146 76 21 21 21 146 99 ... Truncated |
Test 44
Verdict: ACCEPTED
input |
---|
200 420 148 63 188 153 10 175 180 129 ... |
correct output |
---|
36 36 16 36 40 40 40 16 40 36 ... |
user output |
---|
36 36 16 36 40 40 40 16 40 36 ... Truncated |
Test 45
Verdict: ACCEPTED
input |
---|
200 587 70 81 153 52 154 41 101 197 47... |
correct output |
---|
114 153 153 114 153 153 153 15... |
user output |
---|
114 153 153 114 153 153 153 15... Truncated |
Test 46
Verdict: ACCEPTED
input |
---|
200 289 175 162 119 135 5 84 180 193 8... |
correct output |
---|
121 86 58 121 36 193 60 58 19 ... |
user output |
---|
121 86 58 121 36 193 60 58 19 ... Truncated |
Test 47
Verdict: ACCEPTED
input |
---|
200 558 185 92 21 164 74 113 14 7 105 ... |
correct output |
---|
57 13 107 57 13 107 13 107 103... |
user output |
---|
57 13 107 57 13 107 13 107 103... Truncated |
Test 48
Verdict: ACCEPTED
input |
---|
200 230 160 75 25 34 30 21 6 62 146 70... |
correct output |
---|
119 189 8 44 44 162 44 30 44 1... |
user output |
---|
119 189 8 44 44 162 44 30 44 1... Truncated |
Test 49
Verdict: ACCEPTED
input |
---|
200 550 42 57 2 119 56 14 142 191 60 4... |
correct output |
---|
116 118 157 118 116 157 112 11... |
user output |
---|
116 118 157 118 116 157 112 11... Truncated |
Test 50
Verdict: ACCEPTED
input |
---|
200 204 30 86 162 36 29 12 145 195 134... |
correct output |
---|
34 59 48 34 179 179 179 48 152... |
user output |
---|
34 59 48 34 179 179 179 48 152... Truncated |
Test 51
Verdict: ACCEPTED
input |
---|
1000 2098 934 30 933 998 498 379 198 40 ... |
correct output |
---|
960 739 233 960 739 233 739 23... |
user output |
---|
960 739 233 960 739 233 739 23... Truncated |
Test 52
Verdict: ACCEPTED
input |
---|
1000 1834 999 646 500 189 865 410 433 60... |
correct output |
---|
885 885 210 58 184 417 417 210... |
user output |
---|
885 885 210 58 184 417 417 210... Truncated |
Test 53
Verdict: ACCEPTED
input |
---|
1000 1872 505 849 714 811 82 503 751 709... |
correct output |
---|
756 71 278 989 483 874 967 286... |
user output |
---|
756 71 278 989 483 874 967 286... Truncated |
Test 54
Verdict: ACCEPTED
input |
---|
1000 2102 960 913 723 153 863 296 956 46... |
correct output |
---|
877 788 969 53 961 844 889 95 ... |
user output |
---|
877 788 969 53 961 844 889 95 ... Truncated |
Test 55
Verdict: ACCEPTED
input |
---|
1000 2935 254 975 564 356 133 485 340 30... |
correct output |
---|
462 471 752 462 117 117 117 75... |
user output |
---|
462 471 752 462 117 117 117 75... Truncated |
Test 56
Verdict: ACCEPTED
input |
---|
1000 1444 919 660 119 789 842 648 604 11... |
correct output |
---|
272 308 541 741 744 541 404 83... |
user output |
---|
272 308 541 741 744 541 404 83... Truncated |
Test 57
Verdict: ACCEPTED
input |
---|
1000 2786 925 970 421 164 995 689 783 21... |
correct output |
---|
423 396 886 423 118 118 118 88... |
user output |
---|
423 396 886 423 118 118 118 88... Truncated |
Test 58
Verdict: ACCEPTED
input |
---|
1000 1152 155 242 735 833 912 180 639 80... |
correct output |
---|
547 130 873 547 130 873 130 87... |
user output |
---|
547 130 873 547 130 873 130 87... Truncated |
Test 59
Verdict: ACCEPTED
input |
---|
1000 2747 565 852 547 211 925 244 335 32... |
correct output |
---|
965 581 558 581 852 484 224 61... |
user output |
---|
965 581 558 581 852 484 224 61... Truncated |
Test 60
Verdict: ACCEPTED
input |
---|
1000 1020 821 625 397 588 289 372 469 30... |
correct output |
---|
491 891 784 116 698 287 711 52... |
user output |
---|
491 891 784 116 698 287 711 52... Truncated |
Test 61
Verdict: ACCEPTED
input |
---|
100000 100000 26990 68204 21904 3028 29287 1... |
correct output |
---|
6989 36001 68282 32295 75083 5... |
user output |
---|
6989 36001 68282 32295 75083 5... Truncated |
Test 62
Verdict: ACCEPTED
input |
---|
100000 100000 13228 17398 79610 18457 92126 ... |
correct output |
---|
85422 34285 24843 40734 50094 ... |
user output |
---|
85422 34285 24843 40734 50094 ... Truncated |
Test 63
Verdict: ACCEPTED
input |
---|
100000 100000 11080 55900 74628 73314 33646 ... |
correct output |
---|
48679 3060 97205 31406 48488 7... |
user output |
---|
48679 3060 97205 31406 48488 7... Truncated |
Test 64
Verdict: ACCEPTED
input |
---|
100000 100000 96918 48776 71938 59265 12094 ... |
correct output |
---|
50083 27613 20102 27613 12216 ... |
user output |
---|
50083 27613 20102 27613 12216 ... Truncated |
Test 65
Verdict: ACCEPTED
input |
---|
100000 100000 861 54027 8497 56549 74351 180... |
correct output |
---|
37517 7697 66294 35895 68112 4... |
user output |
---|
37517 7697 66294 35895 68112 4... Truncated |
Test 66
Verdict: ACCEPTED
input |
---|
100000 100000 94335 18669 83747 67315 56026 ... |
correct output |
---|
64204 74411 86031 20050 87068 ... |
user output |
---|
64204 74411 86031 20050 87068 ... Truncated |
Test 67
Verdict: ACCEPTED
input |
---|
100000 100000 70439 82301 50793 35505 51484 ... |
correct output |
---|
51403 83667 50017 91054 47448 ... |
user output |
---|
51403 83667 50017 91054 47448 ... Truncated |
Test 68
Verdict: ACCEPTED
input |
---|
100000 100000 1658 37819 55518 34140 46481 2... |
correct output |
---|
27290 75822 76263 59416 31480 ... |
user output |
---|
27290 75822 76263 59416 31480 ... Truncated |
Test 69
Verdict: ACCEPTED
input |
---|
100000 100000 47136 94209 59915 78143 78636 ... |
correct output |
---|
88634 32371 40082 48974 13288 ... |
user output |
---|
88634 32371 40082 48974 13288 ... Truncated |
Test 70
Verdict: ACCEPTED
input |
---|
100000 100000 39437 57474 60243 20923 38668 ... |
correct output |
---|
23653 50188 81237 25631 79750 ... |
user output |
---|
23653 50188 81237 25631 79750 ... Truncated |