#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5, kx=41;
#define ll long long
ll n, u, v, q, l, h[nx], lz[kx][nx], pa[nx], t, x, ds, w;
vector<ll> d[nx];
void dfs(int u, int p)
{
pa[u]=p;
for (auto v:d[u]) if (v!=p) dfs(v, u);
}
void update(int u, ll ds, ll w)
{
if (ds==0) return lz[0][u]=(lz[0][u]*w)%l, void();
if (pa[u]==u) for (int i=0; i<=ds; i++) lz[i][u]=(lz[i][u]*w)%l;
else lz[ds][u]=(lz[ds][u]*w)%l, lz[ds-1][u]=(lz[ds-1][u]*w)%l, update(pa[u], ds-1, w);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>l;
for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
for (int i=1; i<=n; i++) cin>>h[i];
for (int i=0; i<kx; i++) for (int j=1; j<=n; j++) lz[i][j]=1;
dfs(1, 1);
cin>>q;
while (q--)
{
cin>>t;
if (t==1) cin>>x>>ds>>w, update(x, ds, w);
else
{
cin>>u;
ll lvl=0, res=h[u];
while (lvl<=40&&pa[u]!=u) res=(res*lz[lvl][u])%l, u=pa[u], lvl++;
if (pa[u]==u&&lvl<=40) res=(res*lz[lvl][u])%l;
cout<<res<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5468 KB |
Output is correct |
2 |
Correct |
2 ms |
5468 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
3 ms |
5740 KB |
Output is correct |
5 |
Correct |
2 ms |
5720 KB |
Output is correct |
6 |
Correct |
2 ms |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
3 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5468 KB |
Output is correct |
10 |
Correct |
2 ms |
5468 KB |
Output is correct |
11 |
Correct |
2 ms |
5468 KB |
Output is correct |
12 |
Correct |
2 ms |
5468 KB |
Output is correct |
13 |
Correct |
2 ms |
5468 KB |
Output is correct |
14 |
Correct |
2 ms |
5468 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
2 ms |
5432 KB |
Output is correct |
17 |
Correct |
2 ms |
5468 KB |
Output is correct |
18 |
Correct |
2 ms |
5468 KB |
Output is correct |
19 |
Correct |
2 ms |
5468 KB |
Output is correct |
20 |
Correct |
2 ms |
5464 KB |
Output is correct |
21 |
Correct |
2 ms |
5424 KB |
Output is correct |
22 |
Correct |
3 ms |
5468 KB |
Output is correct |
23 |
Correct |
3 ms |
5468 KB |
Output is correct |
24 |
Correct |
3 ms |
5468 KB |
Output is correct |
25 |
Correct |
3 ms |
5468 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
2 ms |
5468 KB |
Output is correct |
28 |
Correct |
2 ms |
5468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5212 KB |
Output is correct |
2 |
Correct |
434 ms |
90132 KB |
Output is correct |
3 |
Correct |
222 ms |
89756 KB |
Output is correct |
4 |
Correct |
352 ms |
91728 KB |
Output is correct |
5 |
Correct |
336 ms |
89796 KB |
Output is correct |
6 |
Correct |
214 ms |
89424 KB |
Output is correct |
7 |
Correct |
225 ms |
90292 KB |
Output is correct |
8 |
Correct |
151 ms |
91604 KB |
Output is correct |
9 |
Correct |
486 ms |
95060 KB |
Output is correct |
10 |
Correct |
236 ms |
95168 KB |
Output is correct |
11 |
Correct |
454 ms |
91220 KB |
Output is correct |
12 |
Correct |
217 ms |
91732 KB |
Output is correct |
13 |
Correct |
145 ms |
91836 KB |
Output is correct |
14 |
Correct |
152 ms |
92084 KB |
Output is correct |
15 |
Correct |
161 ms |
91576 KB |
Output is correct |
16 |
Correct |
153 ms |
91984 KB |
Output is correct |
17 |
Correct |
172 ms |
92496 KB |
Output is correct |
18 |
Correct |
2 ms |
5468 KB |
Output is correct |
19 |
Correct |
3 ms |
5468 KB |
Output is correct |
20 |
Correct |
2 ms |
5468 KB |
Output is correct |
21 |
Correct |
2 ms |
5428 KB |
Output is correct |
22 |
Correct |
2 ms |
5468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5212 KB |
Output is correct |
2 |
Correct |
434 ms |
90132 KB |
Output is correct |
3 |
Correct |
222 ms |
89756 KB |
Output is correct |
4 |
Correct |
352 ms |
91728 KB |
Output is correct |
5 |
Correct |
336 ms |
89796 KB |
Output is correct |
6 |
Correct |
214 ms |
89424 KB |
Output is correct |
7 |
Correct |
225 ms |
90292 KB |
Output is correct |
8 |
Correct |
151 ms |
91604 KB |
Output is correct |
9 |
Correct |
486 ms |
95060 KB |
Output is correct |
10 |
Correct |
236 ms |
95168 KB |
Output is correct |
11 |
Correct |
454 ms |
91220 KB |
Output is correct |
12 |
Correct |
217 ms |
91732 KB |
Output is correct |
13 |
Correct |
145 ms |
91836 KB |
Output is correct |
14 |
Correct |
152 ms |
92084 KB |
Output is correct |
15 |
Correct |
161 ms |
91576 KB |
Output is correct |
16 |
Correct |
153 ms |
91984 KB |
Output is correct |
17 |
Correct |
172 ms |
92496 KB |
Output is correct |
18 |
Correct |
2 ms |
5468 KB |
Output is correct |
19 |
Correct |
3 ms |
5468 KB |
Output is correct |
20 |
Correct |
2 ms |
5468 KB |
Output is correct |
21 |
Correct |
2 ms |
5428 KB |
Output is correct |
22 |
Correct |
2 ms |
5468 KB |
Output is correct |
23 |
Correct |
2 ms |
5464 KB |
Output is correct |
24 |
Correct |
463 ms |
91356 KB |
Output is correct |
25 |
Correct |
241 ms |
91472 KB |
Output is correct |
26 |
Correct |
378 ms |
95316 KB |
Output is correct |
27 |
Correct |
378 ms |
91556 KB |
Output is correct |
28 |
Correct |
236 ms |
91876 KB |
Output is correct |
29 |
Correct |
210 ms |
81744 KB |
Output is correct |
30 |
Correct |
168 ms |
90048 KB |
Output is correct |
31 |
Correct |
479 ms |
93008 KB |
Output is correct |
32 |
Correct |
234 ms |
93188 KB |
Output is correct |
33 |
Correct |
438 ms |
86348 KB |
Output is correct |
34 |
Correct |
222 ms |
80420 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
5468 KB |
Output is correct |
37 |
Correct |
2 ms |
5468 KB |
Output is correct |
38 |
Correct |
4 ms |
5468 KB |
Output is correct |
39 |
Correct |
2 ms |
5468 KB |
Output is correct |
40 |
Correct |
2 ms |
5444 KB |
Output is correct |
41 |
Correct |
2 ms |
5208 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
43 |
Correct |
2 ms |
5212 KB |
Output is correct |
44 |
Correct |
2 ms |
5468 KB |
Output is correct |
45 |
Correct |
2 ms |
5212 KB |
Output is correct |
46 |
Correct |
2 ms |
5468 KB |
Output is correct |
47 |
Correct |
2 ms |
5468 KB |
Output is correct |
48 |
Correct |
2 ms |
5468 KB |
Output is correct |
49 |
Correct |
2 ms |
5468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5468 KB |
Output is correct |
2 |
Correct |
513 ms |
84512 KB |
Output is correct |
3 |
Correct |
571 ms |
90196 KB |
Output is correct |
4 |
Correct |
456 ms |
90084 KB |
Output is correct |
5 |
Correct |
420 ms |
87124 KB |
Output is correct |
6 |
Correct |
250 ms |
88148 KB |
Output is correct |
7 |
Correct |
228 ms |
89172 KB |
Output is correct |
8 |
Correct |
171 ms |
89412 KB |
Output is correct |
9 |
Correct |
512 ms |
90960 KB |
Output is correct |
10 |
Correct |
579 ms |
92452 KB |
Output is correct |
11 |
Correct |
475 ms |
88480 KB |
Output is correct |
12 |
Correct |
500 ms |
89340 KB |
Output is correct |
13 |
Correct |
349 ms |
90260 KB |
Output is correct |
14 |
Correct |
369 ms |
91060 KB |
Output is correct |
15 |
Correct |
2 ms |
5464 KB |
Output is correct |
16 |
Correct |
2 ms |
5468 KB |
Output is correct |
17 |
Correct |
2 ms |
5420 KB |
Output is correct |
18 |
Correct |
2 ms |
5424 KB |
Output is correct |
19 |
Correct |
2 ms |
5464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5212 KB |
Output is correct |
2 |
Correct |
520 ms |
88772 KB |
Output is correct |
3 |
Correct |
540 ms |
87148 KB |
Output is correct |
4 |
Correct |
454 ms |
90452 KB |
Output is correct |
5 |
Correct |
425 ms |
88496 KB |
Output is correct |
6 |
Correct |
263 ms |
89684 KB |
Output is correct |
7 |
Correct |
241 ms |
90196 KB |
Output is correct |
8 |
Correct |
180 ms |
90468 KB |
Output is correct |
9 |
Correct |
513 ms |
94804 KB |
Output is correct |
10 |
Correct |
543 ms |
93200 KB |
Output is correct |
11 |
Correct |
485 ms |
91220 KB |
Output is correct |
12 |
Correct |
520 ms |
89428 KB |
Output is correct |
13 |
Correct |
333 ms |
90180 KB |
Output is correct |
14 |
Correct |
362 ms |
91220 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
2 ms |
5364 KB |
Output is correct |
17 |
Correct |
2 ms |
5468 KB |
Output is correct |
18 |
Correct |
2 ms |
5468 KB |
Output is correct |
19 |
Correct |
2 ms |
5468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5468 KB |
Output is correct |
2 |
Correct |
2 ms |
5468 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
3 ms |
5740 KB |
Output is correct |
5 |
Correct |
2 ms |
5720 KB |
Output is correct |
6 |
Correct |
2 ms |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
3 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5468 KB |
Output is correct |
10 |
Correct |
2 ms |
5468 KB |
Output is correct |
11 |
Correct |
2 ms |
5468 KB |
Output is correct |
12 |
Correct |
2 ms |
5468 KB |
Output is correct |
13 |
Correct |
2 ms |
5468 KB |
Output is correct |
14 |
Correct |
2 ms |
5468 KB |
Output is correct |
15 |
Correct |
2 ms |
5468 KB |
Output is correct |
16 |
Correct |
2 ms |
5432 KB |
Output is correct |
17 |
Correct |
2 ms |
5468 KB |
Output is correct |
18 |
Correct |
2 ms |
5468 KB |
Output is correct |
19 |
Correct |
2 ms |
5468 KB |
Output is correct |
20 |
Correct |
2 ms |
5464 KB |
Output is correct |
21 |
Correct |
2 ms |
5424 KB |
Output is correct |
22 |
Correct |
3 ms |
5468 KB |
Output is correct |
23 |
Correct |
3 ms |
5468 KB |
Output is correct |
24 |
Correct |
3 ms |
5468 KB |
Output is correct |
25 |
Correct |
3 ms |
5468 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
2 ms |
5468 KB |
Output is correct |
28 |
Correct |
2 ms |
5468 KB |
Output is correct |
29 |
Correct |
2 ms |
5212 KB |
Output is correct |
30 |
Correct |
434 ms |
90132 KB |
Output is correct |
31 |
Correct |
222 ms |
89756 KB |
Output is correct |
32 |
Correct |
352 ms |
91728 KB |
Output is correct |
33 |
Correct |
336 ms |
89796 KB |
Output is correct |
34 |
Correct |
214 ms |
89424 KB |
Output is correct |
35 |
Correct |
225 ms |
90292 KB |
Output is correct |
36 |
Correct |
151 ms |
91604 KB |
Output is correct |
37 |
Correct |
486 ms |
95060 KB |
Output is correct |
38 |
Correct |
236 ms |
95168 KB |
Output is correct |
39 |
Correct |
454 ms |
91220 KB |
Output is correct |
40 |
Correct |
217 ms |
91732 KB |
Output is correct |
41 |
Correct |
145 ms |
91836 KB |
Output is correct |
42 |
Correct |
152 ms |
92084 KB |
Output is correct |
43 |
Correct |
161 ms |
91576 KB |
Output is correct |
44 |
Correct |
153 ms |
91984 KB |
Output is correct |
45 |
Correct |
172 ms |
92496 KB |
Output is correct |
46 |
Correct |
2 ms |
5468 KB |
Output is correct |
47 |
Correct |
3 ms |
5468 KB |
Output is correct |
48 |
Correct |
2 ms |
5468 KB |
Output is correct |
49 |
Correct |
2 ms |
5428 KB |
Output is correct |
50 |
Correct |
2 ms |
5468 KB |
Output is correct |
51 |
Correct |
2 ms |
5464 KB |
Output is correct |
52 |
Correct |
463 ms |
91356 KB |
Output is correct |
53 |
Correct |
241 ms |
91472 KB |
Output is correct |
54 |
Correct |
378 ms |
95316 KB |
Output is correct |
55 |
Correct |
378 ms |
91556 KB |
Output is correct |
56 |
Correct |
236 ms |
91876 KB |
Output is correct |
57 |
Correct |
210 ms |
81744 KB |
Output is correct |
58 |
Correct |
168 ms |
90048 KB |
Output is correct |
59 |
Correct |
479 ms |
93008 KB |
Output is correct |
60 |
Correct |
234 ms |
93188 KB |
Output is correct |
61 |
Correct |
438 ms |
86348 KB |
Output is correct |
62 |
Correct |
222 ms |
80420 KB |
Output is correct |
63 |
Correct |
2 ms |
5212 KB |
Output is correct |
64 |
Correct |
2 ms |
5468 KB |
Output is correct |
65 |
Correct |
2 ms |
5468 KB |
Output is correct |
66 |
Correct |
4 ms |
5468 KB |
Output is correct |
67 |
Correct |
2 ms |
5468 KB |
Output is correct |
68 |
Correct |
2 ms |
5444 KB |
Output is correct |
69 |
Correct |
2 ms |
5208 KB |
Output is correct |
70 |
Correct |
2 ms |
5212 KB |
Output is correct |
71 |
Correct |
2 ms |
5212 KB |
Output is correct |
72 |
Correct |
2 ms |
5468 KB |
Output is correct |
73 |
Correct |
2 ms |
5212 KB |
Output is correct |
74 |
Correct |
2 ms |
5468 KB |
Output is correct |
75 |
Correct |
2 ms |
5468 KB |
Output is correct |
76 |
Correct |
2 ms |
5468 KB |
Output is correct |
77 |
Correct |
2 ms |
5468 KB |
Output is correct |
78 |
Correct |
2 ms |
5468 KB |
Output is correct |
79 |
Correct |
513 ms |
84512 KB |
Output is correct |
80 |
Correct |
571 ms |
90196 KB |
Output is correct |
81 |
Correct |
456 ms |
90084 KB |
Output is correct |
82 |
Correct |
420 ms |
87124 KB |
Output is correct |
83 |
Correct |
250 ms |
88148 KB |
Output is correct |
84 |
Correct |
228 ms |
89172 KB |
Output is correct |
85 |
Correct |
171 ms |
89412 KB |
Output is correct |
86 |
Correct |
512 ms |
90960 KB |
Output is correct |
87 |
Correct |
579 ms |
92452 KB |
Output is correct |
88 |
Correct |
475 ms |
88480 KB |
Output is correct |
89 |
Correct |
500 ms |
89340 KB |
Output is correct |
90 |
Correct |
349 ms |
90260 KB |
Output is correct |
91 |
Correct |
369 ms |
91060 KB |
Output is correct |
92 |
Correct |
2 ms |
5464 KB |
Output is correct |
93 |
Correct |
2 ms |
5468 KB |
Output is correct |
94 |
Correct |
2 ms |
5420 KB |
Output is correct |
95 |
Correct |
2 ms |
5424 KB |
Output is correct |
96 |
Correct |
2 ms |
5464 KB |
Output is correct |
97 |
Correct |
3 ms |
5212 KB |
Output is correct |
98 |
Correct |
520 ms |
88772 KB |
Output is correct |
99 |
Correct |
540 ms |
87148 KB |
Output is correct |
100 |
Correct |
454 ms |
90452 KB |
Output is correct |
101 |
Correct |
425 ms |
88496 KB |
Output is correct |
102 |
Correct |
263 ms |
89684 KB |
Output is correct |
103 |
Correct |
241 ms |
90196 KB |
Output is correct |
104 |
Correct |
180 ms |
90468 KB |
Output is correct |
105 |
Correct |
513 ms |
94804 KB |
Output is correct |
106 |
Correct |
543 ms |
93200 KB |
Output is correct |
107 |
Correct |
485 ms |
91220 KB |
Output is correct |
108 |
Correct |
520 ms |
89428 KB |
Output is correct |
109 |
Correct |
333 ms |
90180 KB |
Output is correct |
110 |
Correct |
362 ms |
91220 KB |
Output is correct |
111 |
Correct |
2 ms |
5468 KB |
Output is correct |
112 |
Correct |
2 ms |
5364 KB |
Output is correct |
113 |
Correct |
2 ms |
5468 KB |
Output is correct |
114 |
Correct |
2 ms |
5468 KB |
Output is correct |
115 |
Correct |
2 ms |
5468 KB |
Output is correct |
116 |
Correct |
482 ms |
89328 KB |
Output is correct |
117 |
Correct |
517 ms |
91992 KB |
Output is correct |
118 |
Correct |
444 ms |
95352 KB |
Output is correct |
119 |
Correct |
422 ms |
91828 KB |
Output is correct |
120 |
Correct |
268 ms |
91476 KB |
Output is correct |
121 |
Correct |
236 ms |
92240 KB |
Output is correct |
122 |
Correct |
184 ms |
92348 KB |
Output is correct |
123 |
Correct |
490 ms |
94504 KB |
Output is correct |
124 |
Correct |
588 ms |
93760 KB |
Output is correct |
125 |
Correct |
473 ms |
90676 KB |
Output is correct |
126 |
Correct |
492 ms |
91988 KB |
Output is correct |
127 |
Correct |
515 ms |
92496 KB |
Output is correct |
128 |
Correct |
341 ms |
93008 KB |
Output is correct |
129 |
Correct |
347 ms |
94032 KB |
Output is correct |