# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
561343 | 2022-05-12T16:35:49 Z | hibiki | Sprinkler (JOI22_sprinkler) | C++11 | 1180 ms | 94760 KB |
#include<bits/stdc++.h> using namespace std; #define pb push_back #define f first #define s second int n,q,fa[200005]; long long mod,h[200005]; long long mul[200005][42]; vector<int> v[200005]; void dfs(int nw,int pre) { fa[nw] = pre; for(auto go: v[nw]) { if(go == pre) continue; dfs(go,nw); } } void update(int nw,int left,long long w) { mul[nw][left] *= w; mul[nw][left] %= mod; if(left == 0) return ; if(fa[nw] == -1) { for(int i = left -1; i >= 0; i--) { mul[nw][i] *= w; mul[nw][i] %= mod; } return ; } mul[nw][left - 1] *= w; mul[nw][left - 1] %= mod; update(fa[nw],left - 1,w); } long long query(int nw,int dis) { long long ret = 1ll; ret *= mul[nw][dis]; ret %= mod; if(dis == 41 || fa[nw] == -1) return ret; long long pre = query(fa[nw],dis + 1); pre %= mod; ret *= pre; ret %= mod; return ret; } int main() { // initialize for(int i = 0; i < 200005; i++) for(int j = 0; j < 42; j++) mul[i][j] = 1ll; // input scanf("%d %lld",&n,&mod); for(int i = 0; i < n - 1; i++) { int a,b; scanf("%d %d",&a,&b); v[a].pb(b); v[b].pb(a); } for(int i = 1; i <= n; i++) scanf("%lld",&h[i]); dfs(1,-1); scanf("%d",&q); for(int i = 0; i < q; i++) { int t; scanf("%d",&t); if(t == 1) { int x,d; long long w; scanf("%d %d %lld",&x,&d,&w); w %= mod; update(x,d,w); } else { int x; scanf("%d",&x); long long ans = h[x] * query(x,0); ans %= mod; printf("%lld\n",ans); } } return 0; } /* 16 12 1 2 2 3 2 4 3 5 3 6 4 7 4 8 5 9 5 10 6 11 8 12 10 13 10 14 10 15 11 16 2 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 70860 KB | Output is correct |
2 | Correct | 37 ms | 70688 KB | Output is correct |
3 | Correct | 34 ms | 70744 KB | Output is correct |
4 | Correct | 34 ms | 70704 KB | Output is correct |
5 | Correct | 36 ms | 70780 KB | Output is correct |
6 | Correct | 33 ms | 70812 KB | Output is correct |
7 | Correct | 33 ms | 70732 KB | Output is correct |
8 | Correct | 31 ms | 70752 KB | Output is correct |
9 | Correct | 33 ms | 70652 KB | Output is correct |
10 | Correct | 34 ms | 70756 KB | Output is correct |
11 | Correct | 35 ms | 70652 KB | Output is correct |
12 | Correct | 31 ms | 70740 KB | Output is correct |
13 | Correct | 31 ms | 70672 KB | Output is correct |
14 | Correct | 31 ms | 70748 KB | Output is correct |
15 | Correct | 32 ms | 70704 KB | Output is correct |
16 | Correct | 32 ms | 70644 KB | Output is correct |
17 | Correct | 31 ms | 70756 KB | Output is correct |
18 | Correct | 34 ms | 70732 KB | Output is correct |
19 | Correct | 38 ms | 70756 KB | Output is correct |
20 | Correct | 39 ms | 70676 KB | Output is correct |
21 | Correct | 31 ms | 70732 KB | Output is correct |
22 | Correct | 31 ms | 70724 KB | Output is correct |
23 | Correct | 31 ms | 70740 KB | Output is correct |
24 | Correct | 32 ms | 70740 KB | Output is correct |
25 | Correct | 32 ms | 70684 KB | Output is correct |
26 | Correct | 34 ms | 70764 KB | Output is correct |
27 | Correct | 34 ms | 70732 KB | Output is correct |
28 | Correct | 41 ms | 70748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 70740 KB | Output is correct |
2 | Correct | 745 ms | 82984 KB | Output is correct |
3 | Correct | 417 ms | 84024 KB | Output is correct |
4 | Correct | 643 ms | 89748 KB | Output is correct |
5 | Correct | 620 ms | 86800 KB | Output is correct |
6 | Correct | 435 ms | 87392 KB | Output is correct |
7 | Correct | 401 ms | 86960 KB | Output is correct |
8 | Correct | 357 ms | 87808 KB | Output is correct |
9 | Correct | 839 ms | 92952 KB | Output is correct |
10 | Correct | 514 ms | 87824 KB | Output is correct |
11 | Correct | 762 ms | 88484 KB | Output is correct |
12 | Correct | 470 ms | 84920 KB | Output is correct |
13 | Correct | 304 ms | 84028 KB | Output is correct |
14 | Correct | 302 ms | 83792 KB | Output is correct |
15 | Correct | 331 ms | 81752 KB | Output is correct |
16 | Correct | 339 ms | 85604 KB | Output is correct |
17 | Correct | 302 ms | 86076 KB | Output is correct |
18 | Correct | 32 ms | 70732 KB | Output is correct |
19 | Correct | 32 ms | 70712 KB | Output is correct |
20 | Correct | 32 ms | 70760 KB | Output is correct |
21 | Correct | 40 ms | 70692 KB | Output is correct |
22 | Correct | 35 ms | 70704 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 70740 KB | Output is correct |
2 | Correct | 745 ms | 82984 KB | Output is correct |
3 | Correct | 417 ms | 84024 KB | Output is correct |
4 | Correct | 643 ms | 89748 KB | Output is correct |
5 | Correct | 620 ms | 86800 KB | Output is correct |
6 | Correct | 435 ms | 87392 KB | Output is correct |
7 | Correct | 401 ms | 86960 KB | Output is correct |
8 | Correct | 357 ms | 87808 KB | Output is correct |
9 | Correct | 839 ms | 92952 KB | Output is correct |
10 | Correct | 514 ms | 87824 KB | Output is correct |
11 | Correct | 762 ms | 88484 KB | Output is correct |
12 | Correct | 470 ms | 84920 KB | Output is correct |
13 | Correct | 304 ms | 84028 KB | Output is correct |
14 | Correct | 302 ms | 83792 KB | Output is correct |
15 | Correct | 331 ms | 81752 KB | Output is correct |
16 | Correct | 339 ms | 85604 KB | Output is correct |
17 | Correct | 302 ms | 86076 KB | Output is correct |
18 | Correct | 32 ms | 70732 KB | Output is correct |
19 | Correct | 32 ms | 70712 KB | Output is correct |
20 | Correct | 32 ms | 70760 KB | Output is correct |
21 | Correct | 40 ms | 70692 KB | Output is correct |
22 | Correct | 35 ms | 70704 KB | Output is correct |
23 | Correct | 31 ms | 70764 KB | Output is correct |
24 | Correct | 792 ms | 88076 KB | Output is correct |
25 | Correct | 526 ms | 83304 KB | Output is correct |
26 | Correct | 718 ms | 89820 KB | Output is correct |
27 | Correct | 684 ms | 85596 KB | Output is correct |
28 | Correct | 482 ms | 85840 KB | Output is correct |
29 | Correct | 502 ms | 85628 KB | Output is correct |
30 | Correct | 407 ms | 86284 KB | Output is correct |
31 | Correct | 949 ms | 91020 KB | Output is correct |
32 | Correct | 577 ms | 87604 KB | Output is correct |
33 | Correct | 922 ms | 87992 KB | Output is correct |
34 | Correct | 569 ms | 85476 KB | Output is correct |
35 | Correct | 47 ms | 70716 KB | Output is correct |
36 | Correct | 49 ms | 70732 KB | Output is correct |
37 | Correct | 44 ms | 70768 KB | Output is correct |
38 | Correct | 48 ms | 70720 KB | Output is correct |
39 | Correct | 35 ms | 70672 KB | Output is correct |
40 | Correct | 40 ms | 70692 KB | Output is correct |
41 | Correct | 33 ms | 70732 KB | Output is correct |
42 | Correct | 34 ms | 70716 KB | Output is correct |
43 | Correct | 42 ms | 70652 KB | Output is correct |
44 | Correct | 37 ms | 70732 KB | Output is correct |
45 | Correct | 43 ms | 70752 KB | Output is correct |
46 | Correct | 33 ms | 70672 KB | Output is correct |
47 | Correct | 48 ms | 70676 KB | Output is correct |
48 | Correct | 48 ms | 70720 KB | Output is correct |
49 | Correct | 35 ms | 70692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 70696 KB | Output is correct |
2 | Correct | 903 ms | 84844 KB | Output is correct |
3 | Correct | 876 ms | 83028 KB | Output is correct |
4 | Correct | 849 ms | 83628 KB | Output is correct |
5 | Correct | 825 ms | 79820 KB | Output is correct |
6 | Correct | 558 ms | 80068 KB | Output is correct |
7 | Correct | 528 ms | 80108 KB | Output is correct |
8 | Correct | 421 ms | 80504 KB | Output is correct |
9 | Correct | 1090 ms | 83436 KB | Output is correct |
10 | Correct | 986 ms | 83680 KB | Output is correct |
11 | Correct | 1180 ms | 80128 KB | Output is correct |
12 | Correct | 985 ms | 79588 KB | Output is correct |
13 | Correct | 579 ms | 80372 KB | Output is correct |
14 | Correct | 633 ms | 80780 KB | Output is correct |
15 | Correct | 36 ms | 70728 KB | Output is correct |
16 | Correct | 41 ms | 70684 KB | Output is correct |
17 | Correct | 49 ms | 70708 KB | Output is correct |
18 | Correct | 40 ms | 70668 KB | Output is correct |
19 | Correct | 48 ms | 70732 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 70644 KB | Output is correct |
2 | Correct | 1171 ms | 86012 KB | Output is correct |
3 | Correct | 1006 ms | 82172 KB | Output is correct |
4 | Correct | 997 ms | 92120 KB | Output is correct |
5 | Correct | 976 ms | 89472 KB | Output is correct |
6 | Correct | 602 ms | 89548 KB | Output is correct |
7 | Correct | 671 ms | 89360 KB | Output is correct |
8 | Correct | 365 ms | 89784 KB | Output is correct |
9 | Correct | 1098 ms | 94760 KB | Output is correct |
10 | Correct | 921 ms | 92672 KB | Output is correct |
11 | Correct | 1150 ms | 90292 KB | Output is correct |
12 | Correct | 945 ms | 88544 KB | Output is correct |
13 | Correct | 651 ms | 89680 KB | Output is correct |
14 | Correct | 659 ms | 90068 KB | Output is correct |
15 | Correct | 38 ms | 70728 KB | Output is correct |
16 | Correct | 43 ms | 70684 KB | Output is correct |
17 | Correct | 37 ms | 70756 KB | Output is correct |
18 | Correct | 47 ms | 70760 KB | Output is correct |
19 | Correct | 40 ms | 70748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 70860 KB | Output is correct |
2 | Correct | 37 ms | 70688 KB | Output is correct |
3 | Correct | 34 ms | 70744 KB | Output is correct |
4 | Correct | 34 ms | 70704 KB | Output is correct |
5 | Correct | 36 ms | 70780 KB | Output is correct |
6 | Correct | 33 ms | 70812 KB | Output is correct |
7 | Correct | 33 ms | 70732 KB | Output is correct |
8 | Correct | 31 ms | 70752 KB | Output is correct |
9 | Correct | 33 ms | 70652 KB | Output is correct |
10 | Correct | 34 ms | 70756 KB | Output is correct |
11 | Correct | 35 ms | 70652 KB | Output is correct |
12 | Correct | 31 ms | 70740 KB | Output is correct |
13 | Correct | 31 ms | 70672 KB | Output is correct |
14 | Correct | 31 ms | 70748 KB | Output is correct |
15 | Correct | 32 ms | 70704 KB | Output is correct |
16 | Correct | 32 ms | 70644 KB | Output is correct |
17 | Correct | 31 ms | 70756 KB | Output is correct |
18 | Correct | 34 ms | 70732 KB | Output is correct |
19 | Correct | 38 ms | 70756 KB | Output is correct |
20 | Correct | 39 ms | 70676 KB | Output is correct |
21 | Correct | 31 ms | 70732 KB | Output is correct |
22 | Correct | 31 ms | 70724 KB | Output is correct |
23 | Correct | 31 ms | 70740 KB | Output is correct |
24 | Correct | 32 ms | 70740 KB | Output is correct |
25 | Correct | 32 ms | 70684 KB | Output is correct |
26 | Correct | 34 ms | 70764 KB | Output is correct |
27 | Correct | 34 ms | 70732 KB | Output is correct |
28 | Correct | 41 ms | 70748 KB | Output is correct |
29 | Correct | 31 ms | 70740 KB | Output is correct |
30 | Correct | 745 ms | 82984 KB | Output is correct |
31 | Correct | 417 ms | 84024 KB | Output is correct |
32 | Correct | 643 ms | 89748 KB | Output is correct |
33 | Correct | 620 ms | 86800 KB | Output is correct |
34 | Correct | 435 ms | 87392 KB | Output is correct |
35 | Correct | 401 ms | 86960 KB | Output is correct |
36 | Correct | 357 ms | 87808 KB | Output is correct |
37 | Correct | 839 ms | 92952 KB | Output is correct |
38 | Correct | 514 ms | 87824 KB | Output is correct |
39 | Correct | 762 ms | 88484 KB | Output is correct |
40 | Correct | 470 ms | 84920 KB | Output is correct |
41 | Correct | 304 ms | 84028 KB | Output is correct |
42 | Correct | 302 ms | 83792 KB | Output is correct |
43 | Correct | 331 ms | 81752 KB | Output is correct |
44 | Correct | 339 ms | 85604 KB | Output is correct |
45 | Correct | 302 ms | 86076 KB | Output is correct |
46 | Correct | 32 ms | 70732 KB | Output is correct |
47 | Correct | 32 ms | 70712 KB | Output is correct |
48 | Correct | 32 ms | 70760 KB | Output is correct |
49 | Correct | 40 ms | 70692 KB | Output is correct |
50 | Correct | 35 ms | 70704 KB | Output is correct |
51 | Correct | 31 ms | 70764 KB | Output is correct |
52 | Correct | 792 ms | 88076 KB | Output is correct |
53 | Correct | 526 ms | 83304 KB | Output is correct |
54 | Correct | 718 ms | 89820 KB | Output is correct |
55 | Correct | 684 ms | 85596 KB | Output is correct |
56 | Correct | 482 ms | 85840 KB | Output is correct |
57 | Correct | 502 ms | 85628 KB | Output is correct |
58 | Correct | 407 ms | 86284 KB | Output is correct |
59 | Correct | 949 ms | 91020 KB | Output is correct |
60 | Correct | 577 ms | 87604 KB | Output is correct |
61 | Correct | 922 ms | 87992 KB | Output is correct |
62 | Correct | 569 ms | 85476 KB | Output is correct |
63 | Correct | 47 ms | 70716 KB | Output is correct |
64 | Correct | 49 ms | 70732 KB | Output is correct |
65 | Correct | 44 ms | 70768 KB | Output is correct |
66 | Correct | 48 ms | 70720 KB | Output is correct |
67 | Correct | 35 ms | 70672 KB | Output is correct |
68 | Correct | 40 ms | 70692 KB | Output is correct |
69 | Correct | 33 ms | 70732 KB | Output is correct |
70 | Correct | 34 ms | 70716 KB | Output is correct |
71 | Correct | 42 ms | 70652 KB | Output is correct |
72 | Correct | 37 ms | 70732 KB | Output is correct |
73 | Correct | 43 ms | 70752 KB | Output is correct |
74 | Correct | 33 ms | 70672 KB | Output is correct |
75 | Correct | 48 ms | 70676 KB | Output is correct |
76 | Correct | 48 ms | 70720 KB | Output is correct |
77 | Correct | 35 ms | 70692 KB | Output is correct |
78 | Correct | 35 ms | 70696 KB | Output is correct |
79 | Correct | 903 ms | 84844 KB | Output is correct |
80 | Correct | 876 ms | 83028 KB | Output is correct |
81 | Correct | 849 ms | 83628 KB | Output is correct |
82 | Correct | 825 ms | 79820 KB | Output is correct |
83 | Correct | 558 ms | 80068 KB | Output is correct |
84 | Correct | 528 ms | 80108 KB | Output is correct |
85 | Correct | 421 ms | 80504 KB | Output is correct |
86 | Correct | 1090 ms | 83436 KB | Output is correct |
87 | Correct | 986 ms | 83680 KB | Output is correct |
88 | Correct | 1180 ms | 80128 KB | Output is correct |
89 | Correct | 985 ms | 79588 KB | Output is correct |
90 | Correct | 579 ms | 80372 KB | Output is correct |
91 | Correct | 633 ms | 80780 KB | Output is correct |
92 | Correct | 36 ms | 70728 KB | Output is correct |
93 | Correct | 41 ms | 70684 KB | Output is correct |
94 | Correct | 49 ms | 70708 KB | Output is correct |
95 | Correct | 40 ms | 70668 KB | Output is correct |
96 | Correct | 48 ms | 70732 KB | Output is correct |
97 | Correct | 41 ms | 70644 KB | Output is correct |
98 | Correct | 1171 ms | 86012 KB | Output is correct |
99 | Correct | 1006 ms | 82172 KB | Output is correct |
100 | Correct | 997 ms | 92120 KB | Output is correct |
101 | Correct | 976 ms | 89472 KB | Output is correct |
102 | Correct | 602 ms | 89548 KB | Output is correct |
103 | Correct | 671 ms | 89360 KB | Output is correct |
104 | Correct | 365 ms | 89784 KB | Output is correct |
105 | Correct | 1098 ms | 94760 KB | Output is correct |
106 | Correct | 921 ms | 92672 KB | Output is correct |
107 | Correct | 1150 ms | 90292 KB | Output is correct |
108 | Correct | 945 ms | 88544 KB | Output is correct |
109 | Correct | 651 ms | 89680 KB | Output is correct |
110 | Correct | 659 ms | 90068 KB | Output is correct |
111 | Correct | 38 ms | 70728 KB | Output is correct |
112 | Correct | 43 ms | 70684 KB | Output is correct |
113 | Correct | 37 ms | 70756 KB | Output is correct |
114 | Correct | 47 ms | 70760 KB | Output is correct |
115 | Correct | 40 ms | 70748 KB | Output is correct |
116 | Correct | 975 ms | 88808 KB | Output is correct |
117 | Correct | 914 ms | 91324 KB | Output is correct |
118 | Correct | 927 ms | 94616 KB | Output is correct |
119 | Correct | 929 ms | 90940 KB | Output is correct |
120 | Correct | 659 ms | 90424 KB | Output is correct |
121 | Correct | 624 ms | 91184 KB | Output is correct |
122 | Correct | 426 ms | 91328 KB | Output is correct |
123 | Correct | 1161 ms | 94552 KB | Output is correct |
124 | Correct | 1123 ms | 94120 KB | Output is correct |
125 | Correct | 1077 ms | 89288 KB | Output is correct |
126 | Correct | 966 ms | 90980 KB | Output is correct |
127 | Correct | 991 ms | 91508 KB | Output is correct |
128 | Correct | 792 ms | 88980 KB | Output is correct |
129 | Correct | 766 ms | 84764 KB | Output is correct |