# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
615122 | 2022-07-31T06:59:31 Z | 조영욱(#8494) | Sprinkler (JOI22_sprinkler) | C++17 | 1089 ms | 94584 KB |
#include <bits/stdc++.h> using namespace std; int n,mod; vector<int> adj[200001]; int par[200001]; long long h[200001]; long long save[200001][41]; void dfs(int v,int prev) { par[v]=prev; for(int i=0;i<adj[v].size();i++) { int nt=adj[v][i]; if (nt!=prev) { dfs(nt,v); } } } int main(void) { scanf("%d %d",&n,&mod); for(int i=1;i<n;i++) { int u,v; scanf("%d %d",&u,&v); adj[u].push_back(v); adj[v].push_back(u); } for(int i=1;i<=n;i++) { scanf("%lld",&h[i]); } dfs(1,-1); for(int i=1;i<=n;i++) { for(int j=0;j<=40;j++) { save[i][j]=1; } } int q; scanf("%d",&q); for(int i=0;i<q;i++) { int type; scanf("%d",&type); if (type==1) { int x,d,w; scanf("%d %d %d",&x,&d,&w); int now=x; for(int i=0;i<=d;i++) { if (now==-1) { break; } save[now][d-i]*=w; save[now][d-i]%=mod; now=par[now]; } } else { int x; scanf("%d",&x); long long ret=h[x]; int now=x; int en=0; for(int j=0;j<=40;j++) { if (par[now]==-1) { for(int k=en;k<=40;k++) { ret*=save[now][k]; ret%=mod; } break; } ret*=save[now][en]; ret%=mod; if (en!=40){ ret*=save[now][en+1]; ret%=mod; } en++; now=par[now]; } printf("%lld\n",ret); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4904 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 3 ms | 5332 KB | Output is correct |
5 | Correct | 18 ms | 5332 KB | Output is correct |
6 | Correct | 4 ms | 5332 KB | Output is correct |
7 | Correct | 4 ms | 5400 KB | Output is correct |
8 | Correct | 13 ms | 5396 KB | Output is correct |
9 | Correct | 3 ms | 4948 KB | Output is correct |
10 | Correct | 3 ms | 4948 KB | Output is correct |
11 | Correct | 3 ms | 4948 KB | Output is correct |
12 | Correct | 3 ms | 4948 KB | Output is correct |
13 | Correct | 4 ms | 4948 KB | Output is correct |
14 | Correct | 3 ms | 5016 KB | Output is correct |
15 | Correct | 3 ms | 4948 KB | Output is correct |
16 | Correct | 4 ms | 5036 KB | Output is correct |
17 | Correct | 4 ms | 5012 KB | Output is correct |
18 | Correct | 4 ms | 4948 KB | Output is correct |
19 | Correct | 3 ms | 4948 KB | Output is correct |
20 | Correct | 3 ms | 4948 KB | Output is correct |
21 | Correct | 3 ms | 4948 KB | Output is correct |
22 | Correct | 5 ms | 5132 KB | Output is correct |
23 | Correct | 4 ms | 5004 KB | Output is correct |
24 | Correct | 4 ms | 5008 KB | Output is correct |
25 | Correct | 4 ms | 5020 KB | Output is correct |
26 | Correct | 3 ms | 5000 KB | Output is correct |
27 | Correct | 3 ms | 5004 KB | Output is correct |
28 | Correct | 3 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 698 ms | 81408 KB | Output is correct |
3 | Correct | 435 ms | 78560 KB | Output is correct |
4 | Correct | 646 ms | 85760 KB | Output is correct |
5 | Correct | 640 ms | 79884 KB | Output is correct |
6 | Correct | 546 ms | 79752 KB | Output is correct |
7 | Correct | 402 ms | 80204 KB | Output is correct |
8 | Correct | 363 ms | 80528 KB | Output is correct |
9 | Correct | 764 ms | 90380 KB | Output is correct |
10 | Correct | 801 ms | 89048 KB | Output is correct |
11 | Correct | 1089 ms | 83972 KB | Output is correct |
12 | Correct | 527 ms | 80772 KB | Output is correct |
13 | Correct | 375 ms | 80656 KB | Output is correct |
14 | Correct | 381 ms | 80704 KB | Output is correct |
15 | Correct | 314 ms | 80644 KB | Output is correct |
16 | Correct | 332 ms | 80592 KB | Output is correct |
17 | Correct | 330 ms | 81220 KB | Output is correct |
18 | Correct | 5 ms | 4948 KB | Output is correct |
19 | Correct | 4 ms | 5012 KB | Output is correct |
20 | Correct | 4 ms | 4948 KB | Output is correct |
21 | Correct | 3 ms | 4948 KB | Output is correct |
22 | Correct | 4 ms | 5012 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 698 ms | 81408 KB | Output is correct |
3 | Correct | 435 ms | 78560 KB | Output is correct |
4 | Correct | 646 ms | 85760 KB | Output is correct |
5 | Correct | 640 ms | 79884 KB | Output is correct |
6 | Correct | 546 ms | 79752 KB | Output is correct |
7 | Correct | 402 ms | 80204 KB | Output is correct |
8 | Correct | 363 ms | 80528 KB | Output is correct |
9 | Correct | 764 ms | 90380 KB | Output is correct |
10 | Correct | 801 ms | 89048 KB | Output is correct |
11 | Correct | 1089 ms | 83972 KB | Output is correct |
12 | Correct | 527 ms | 80772 KB | Output is correct |
13 | Correct | 375 ms | 80656 KB | Output is correct |
14 | Correct | 381 ms | 80704 KB | Output is correct |
15 | Correct | 314 ms | 80644 KB | Output is correct |
16 | Correct | 332 ms | 80592 KB | Output is correct |
17 | Correct | 330 ms | 81220 KB | Output is correct |
18 | Correct | 5 ms | 4948 KB | Output is correct |
19 | Correct | 4 ms | 5012 KB | Output is correct |
20 | Correct | 4 ms | 4948 KB | Output is correct |
21 | Correct | 3 ms | 4948 KB | Output is correct |
22 | Correct | 4 ms | 5012 KB | Output is correct |
23 | Correct | 3 ms | 4948 KB | Output is correct |
24 | Correct | 776 ms | 83368 KB | Output is correct |
25 | Correct | 534 ms | 80164 KB | Output is correct |
26 | Correct | 608 ms | 90380 KB | Output is correct |
27 | Correct | 613 ms | 81752 KB | Output is correct |
28 | Correct | 486 ms | 81424 KB | Output is correct |
29 | Correct | 470 ms | 81100 KB | Output is correct |
30 | Correct | 376 ms | 81692 KB | Output is correct |
31 | Correct | 709 ms | 88736 KB | Output is correct |
32 | Correct | 445 ms | 87648 KB | Output is correct |
33 | Correct | 562 ms | 82648 KB | Output is correct |
34 | Correct | 410 ms | 79432 KB | Output is correct |
35 | Correct | 3 ms | 4948 KB | Output is correct |
36 | Correct | 4 ms | 5012 KB | Output is correct |
37 | Correct | 5 ms | 4960 KB | Output is correct |
38 | Correct | 4 ms | 4948 KB | Output is correct |
39 | Correct | 4 ms | 4948 KB | Output is correct |
40 | Correct | 3 ms | 5012 KB | Output is correct |
41 | Correct | 4 ms | 4948 KB | Output is correct |
42 | Correct | 3 ms | 4948 KB | Output is correct |
43 | Correct | 3 ms | 4948 KB | Output is correct |
44 | Correct | 3 ms | 5004 KB | Output is correct |
45 | Correct | 3 ms | 4948 KB | Output is correct |
46 | Correct | 4 ms | 5012 KB | Output is correct |
47 | Correct | 3 ms | 5008 KB | Output is correct |
48 | Correct | 3 ms | 4948 KB | Output is correct |
49 | Correct | 3 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 684 ms | 87628 KB | Output is correct |
3 | Correct | 714 ms | 86116 KB | Output is correct |
4 | Correct | 653 ms | 88008 KB | Output is correct |
5 | Correct | 611 ms | 80932 KB | Output is correct |
6 | Correct | 484 ms | 81024 KB | Output is correct |
7 | Correct | 439 ms | 81092 KB | Output is correct |
8 | Correct | 339 ms | 81500 KB | Output is correct |
9 | Correct | 726 ms | 87376 KB | Output is correct |
10 | Correct | 733 ms | 88624 KB | Output is correct |
11 | Correct | 621 ms | 81040 KB | Output is correct |
12 | Correct | 620 ms | 80536 KB | Output is correct |
13 | Correct | 422 ms | 81380 KB | Output is correct |
14 | Correct | 464 ms | 81848 KB | Output is correct |
15 | Correct | 3 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 4948 KB | Output is correct |
17 | Correct | 4 ms | 5008 KB | Output is correct |
18 | Correct | 4 ms | 5012 KB | Output is correct |
19 | Correct | 4 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 697 ms | 87272 KB | Output is correct |
3 | Correct | 666 ms | 84380 KB | Output is correct |
4 | Correct | 633 ms | 87692 KB | Output is correct |
5 | Correct | 563 ms | 82440 KB | Output is correct |
6 | Correct | 538 ms | 82464 KB | Output is correct |
7 | Correct | 490 ms | 82480 KB | Output is correct |
8 | Correct | 432 ms | 82812 KB | Output is correct |
9 | Correct | 691 ms | 92228 KB | Output is correct |
10 | Correct | 694 ms | 89232 KB | Output is correct |
11 | Correct | 860 ms | 83944 KB | Output is correct |
12 | Correct | 646 ms | 80792 KB | Output is correct |
13 | Correct | 462 ms | 81576 KB | Output is correct |
14 | Correct | 471 ms | 81980 KB | Output is correct |
15 | Correct | 3 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 4948 KB | Output is correct |
17 | Correct | 3 ms | 4948 KB | Output is correct |
18 | Correct | 3 ms | 4948 KB | Output is correct |
19 | Correct | 3 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4904 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 3 ms | 5332 KB | Output is correct |
5 | Correct | 18 ms | 5332 KB | Output is correct |
6 | Correct | 4 ms | 5332 KB | Output is correct |
7 | Correct | 4 ms | 5400 KB | Output is correct |
8 | Correct | 13 ms | 5396 KB | Output is correct |
9 | Correct | 3 ms | 4948 KB | Output is correct |
10 | Correct | 3 ms | 4948 KB | Output is correct |
11 | Correct | 3 ms | 4948 KB | Output is correct |
12 | Correct | 3 ms | 4948 KB | Output is correct |
13 | Correct | 4 ms | 4948 KB | Output is correct |
14 | Correct | 3 ms | 5016 KB | Output is correct |
15 | Correct | 3 ms | 4948 KB | Output is correct |
16 | Correct | 4 ms | 5036 KB | Output is correct |
17 | Correct | 4 ms | 5012 KB | Output is correct |
18 | Correct | 4 ms | 4948 KB | Output is correct |
19 | Correct | 3 ms | 4948 KB | Output is correct |
20 | Correct | 3 ms | 4948 KB | Output is correct |
21 | Correct | 3 ms | 4948 KB | Output is correct |
22 | Correct | 5 ms | 5132 KB | Output is correct |
23 | Correct | 4 ms | 5004 KB | Output is correct |
24 | Correct | 4 ms | 5008 KB | Output is correct |
25 | Correct | 4 ms | 5020 KB | Output is correct |
26 | Correct | 3 ms | 5000 KB | Output is correct |
27 | Correct | 3 ms | 5004 KB | Output is correct |
28 | Correct | 3 ms | 4948 KB | Output is correct |
29 | Correct | 3 ms | 4948 KB | Output is correct |
30 | Correct | 698 ms | 81408 KB | Output is correct |
31 | Correct | 435 ms | 78560 KB | Output is correct |
32 | Correct | 646 ms | 85760 KB | Output is correct |
33 | Correct | 640 ms | 79884 KB | Output is correct |
34 | Correct | 546 ms | 79752 KB | Output is correct |
35 | Correct | 402 ms | 80204 KB | Output is correct |
36 | Correct | 363 ms | 80528 KB | Output is correct |
37 | Correct | 764 ms | 90380 KB | Output is correct |
38 | Correct | 801 ms | 89048 KB | Output is correct |
39 | Correct | 1089 ms | 83972 KB | Output is correct |
40 | Correct | 527 ms | 80772 KB | Output is correct |
41 | Correct | 375 ms | 80656 KB | Output is correct |
42 | Correct | 381 ms | 80704 KB | Output is correct |
43 | Correct | 314 ms | 80644 KB | Output is correct |
44 | Correct | 332 ms | 80592 KB | Output is correct |
45 | Correct | 330 ms | 81220 KB | Output is correct |
46 | Correct | 5 ms | 4948 KB | Output is correct |
47 | Correct | 4 ms | 5012 KB | Output is correct |
48 | Correct | 4 ms | 4948 KB | Output is correct |
49 | Correct | 3 ms | 4948 KB | Output is correct |
50 | Correct | 4 ms | 5012 KB | Output is correct |
51 | Correct | 3 ms | 4948 KB | Output is correct |
52 | Correct | 776 ms | 83368 KB | Output is correct |
53 | Correct | 534 ms | 80164 KB | Output is correct |
54 | Correct | 608 ms | 90380 KB | Output is correct |
55 | Correct | 613 ms | 81752 KB | Output is correct |
56 | Correct | 486 ms | 81424 KB | Output is correct |
57 | Correct | 470 ms | 81100 KB | Output is correct |
58 | Correct | 376 ms | 81692 KB | Output is correct |
59 | Correct | 709 ms | 88736 KB | Output is correct |
60 | Correct | 445 ms | 87648 KB | Output is correct |
61 | Correct | 562 ms | 82648 KB | Output is correct |
62 | Correct | 410 ms | 79432 KB | Output is correct |
63 | Correct | 3 ms | 4948 KB | Output is correct |
64 | Correct | 4 ms | 5012 KB | Output is correct |
65 | Correct | 5 ms | 4960 KB | Output is correct |
66 | Correct | 4 ms | 4948 KB | Output is correct |
67 | Correct | 4 ms | 4948 KB | Output is correct |
68 | Correct | 3 ms | 5012 KB | Output is correct |
69 | Correct | 4 ms | 4948 KB | Output is correct |
70 | Correct | 3 ms | 4948 KB | Output is correct |
71 | Correct | 3 ms | 4948 KB | Output is correct |
72 | Correct | 3 ms | 5004 KB | Output is correct |
73 | Correct | 3 ms | 4948 KB | Output is correct |
74 | Correct | 4 ms | 5012 KB | Output is correct |
75 | Correct | 3 ms | 5008 KB | Output is correct |
76 | Correct | 3 ms | 4948 KB | Output is correct |
77 | Correct | 3 ms | 4948 KB | Output is correct |
78 | Correct | 3 ms | 4948 KB | Output is correct |
79 | Correct | 684 ms | 87628 KB | Output is correct |
80 | Correct | 714 ms | 86116 KB | Output is correct |
81 | Correct | 653 ms | 88008 KB | Output is correct |
82 | Correct | 611 ms | 80932 KB | Output is correct |
83 | Correct | 484 ms | 81024 KB | Output is correct |
84 | Correct | 439 ms | 81092 KB | Output is correct |
85 | Correct | 339 ms | 81500 KB | Output is correct |
86 | Correct | 726 ms | 87376 KB | Output is correct |
87 | Correct | 733 ms | 88624 KB | Output is correct |
88 | Correct | 621 ms | 81040 KB | Output is correct |
89 | Correct | 620 ms | 80536 KB | Output is correct |
90 | Correct | 422 ms | 81380 KB | Output is correct |
91 | Correct | 464 ms | 81848 KB | Output is correct |
92 | Correct | 3 ms | 4948 KB | Output is correct |
93 | Correct | 3 ms | 4948 KB | Output is correct |
94 | Correct | 4 ms | 5008 KB | Output is correct |
95 | Correct | 4 ms | 5012 KB | Output is correct |
96 | Correct | 4 ms | 4948 KB | Output is correct |
97 | Correct | 2 ms | 4948 KB | Output is correct |
98 | Correct | 697 ms | 87272 KB | Output is correct |
99 | Correct | 666 ms | 84380 KB | Output is correct |
100 | Correct | 633 ms | 87692 KB | Output is correct |
101 | Correct | 563 ms | 82440 KB | Output is correct |
102 | Correct | 538 ms | 82464 KB | Output is correct |
103 | Correct | 490 ms | 82480 KB | Output is correct |
104 | Correct | 432 ms | 82812 KB | Output is correct |
105 | Correct | 691 ms | 92228 KB | Output is correct |
106 | Correct | 694 ms | 89232 KB | Output is correct |
107 | Correct | 860 ms | 83944 KB | Output is correct |
108 | Correct | 646 ms | 80792 KB | Output is correct |
109 | Correct | 462 ms | 81576 KB | Output is correct |
110 | Correct | 471 ms | 81980 KB | Output is correct |
111 | Correct | 3 ms | 4948 KB | Output is correct |
112 | Correct | 3 ms | 4948 KB | Output is correct |
113 | Correct | 3 ms | 4948 KB | Output is correct |
114 | Correct | 3 ms | 4948 KB | Output is correct |
115 | Correct | 3 ms | 4948 KB | Output is correct |
116 | Correct | 703 ms | 87316 KB | Output is correct |
117 | Correct | 624 ms | 84948 KB | Output is correct |
118 | Correct | 636 ms | 94584 KB | Output is correct |
119 | Correct | 594 ms | 85800 KB | Output is correct |
120 | Correct | 476 ms | 85780 KB | Output is correct |
121 | Correct | 525 ms | 86220 KB | Output is correct |
122 | Correct | 373 ms | 86264 KB | Output is correct |
123 | Correct | 756 ms | 94256 KB | Output is correct |
124 | Correct | 680 ms | 89444 KB | Output is correct |
125 | Correct | 659 ms | 86460 KB | Output is correct |
126 | Correct | 671 ms | 83808 KB | Output is correct |
127 | Correct | 632 ms | 83556 KB | Output is correct |
128 | Correct | 476 ms | 84548 KB | Output is correct |
129 | Correct | 442 ms | 84596 KB | Output is correct |