#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<type1, null_type, less_equal<type1>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const double PI = acos(-1.0);
const double epsilon = 1e-6;
const int N = 2e5+5;
vector<int> g[N];
int par[N];
void dfs(int v, int p){
par[v] = p;
for(auto to : g[v]){
if(to != p) dfs(to, v);
}
}
void solve(){
int n, l; cin >> n >> l;
for(int i = 1; i < n; i++){
int u, v; cin >> u >> v;
g[u].pb(v); g[v].pb(u);
}
vector<vector<int> > dp(n + 1, vector<int>(45, 1));
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
dfs(1, 0);
int q; cin >> q;
while(q--){
int ty; cin >> ty;
if(ty == 1){
int x, d, w; cin >> x >> d >> w;
while(d and par[x]){
dp[x][d] = dp[x][d] * w % l;
dp[x][d - 1] = dp[x][d - 1] * w % l;
x = par[x];
d--;
}
while(d + 1){
dp[x][d] = dp[x][d] * w % l;
d--;
}
}else{
int x; cin >> x;
int ans = a[x];
for(int i = 0; i <= 40 and x; i++){
ans = ans * dp[x][i] % l;
x = par[x];
}
cout << ans << '\n';
}
}
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
}
Compilation message
sprinkler.cpp:72:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
72 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6452 KB |
Output is correct |
4 |
Correct |
3 ms |
7004 KB |
Output is correct |
5 |
Correct |
3 ms |
6812 KB |
Output is correct |
6 |
Correct |
3 ms |
7004 KB |
Output is correct |
7 |
Correct |
3 ms |
7004 KB |
Output is correct |
8 |
Correct |
4 ms |
7004 KB |
Output is correct |
9 |
Correct |
3 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6552 KB |
Output is correct |
18 |
Correct |
3 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6496 KB |
Output is correct |
23 |
Correct |
2 ms |
6548 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6488 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6544 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
536 ms |
100332 KB |
Output is correct |
3 |
Correct |
373 ms |
99016 KB |
Output is correct |
4 |
Correct |
533 ms |
101872 KB |
Output is correct |
5 |
Correct |
391 ms |
99476 KB |
Output is correct |
6 |
Correct |
340 ms |
99516 KB |
Output is correct |
7 |
Correct |
347 ms |
99920 KB |
Output is correct |
8 |
Correct |
267 ms |
99928 KB |
Output is correct |
9 |
Correct |
616 ms |
104052 KB |
Output is correct |
10 |
Correct |
386 ms |
102676 KB |
Output is correct |
11 |
Correct |
551 ms |
100664 KB |
Output is correct |
12 |
Correct |
404 ms |
99052 KB |
Output is correct |
13 |
Correct |
215 ms |
99420 KB |
Output is correct |
14 |
Correct |
202 ms |
99176 KB |
Output is correct |
15 |
Correct |
207 ms |
98644 KB |
Output is correct |
16 |
Correct |
207 ms |
99116 KB |
Output is correct |
17 |
Correct |
221 ms |
99532 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
3 ms |
6748 KB |
Output is correct |
20 |
Correct |
3 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6808 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
536 ms |
100332 KB |
Output is correct |
3 |
Correct |
373 ms |
99016 KB |
Output is correct |
4 |
Correct |
533 ms |
101872 KB |
Output is correct |
5 |
Correct |
391 ms |
99476 KB |
Output is correct |
6 |
Correct |
340 ms |
99516 KB |
Output is correct |
7 |
Correct |
347 ms |
99920 KB |
Output is correct |
8 |
Correct |
267 ms |
99928 KB |
Output is correct |
9 |
Correct |
616 ms |
104052 KB |
Output is correct |
10 |
Correct |
386 ms |
102676 KB |
Output is correct |
11 |
Correct |
551 ms |
100664 KB |
Output is correct |
12 |
Correct |
404 ms |
99052 KB |
Output is correct |
13 |
Correct |
215 ms |
99420 KB |
Output is correct |
14 |
Correct |
202 ms |
99176 KB |
Output is correct |
15 |
Correct |
207 ms |
98644 KB |
Output is correct |
16 |
Correct |
207 ms |
99116 KB |
Output is correct |
17 |
Correct |
221 ms |
99532 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
3 ms |
6748 KB |
Output is correct |
20 |
Correct |
3 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6808 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6548 KB |
Output is correct |
24 |
Correct |
445 ms |
100028 KB |
Output is correct |
25 |
Correct |
335 ms |
98824 KB |
Output is correct |
26 |
Correct |
458 ms |
103252 KB |
Output is correct |
27 |
Correct |
392 ms |
99496 KB |
Output is correct |
28 |
Correct |
296 ms |
99732 KB |
Output is correct |
29 |
Correct |
312 ms |
99540 KB |
Output is correct |
30 |
Correct |
254 ms |
99996 KB |
Output is correct |
31 |
Correct |
613 ms |
102776 KB |
Output is correct |
32 |
Correct |
343 ms |
102428 KB |
Output is correct |
33 |
Correct |
497 ms |
100152 KB |
Output is correct |
34 |
Correct |
324 ms |
98896 KB |
Output is correct |
35 |
Correct |
2 ms |
6488 KB |
Output is correct |
36 |
Correct |
2 ms |
6492 KB |
Output is correct |
37 |
Correct |
2 ms |
6492 KB |
Output is correct |
38 |
Correct |
2 ms |
6492 KB |
Output is correct |
39 |
Correct |
2 ms |
6492 KB |
Output is correct |
40 |
Correct |
2 ms |
6544 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6492 KB |
Output is correct |
43 |
Correct |
2 ms |
6492 KB |
Output is correct |
44 |
Correct |
2 ms |
6492 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6492 KB |
Output is correct |
48 |
Correct |
2 ms |
6492 KB |
Output is correct |
49 |
Correct |
2 ms |
6544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
639 ms |
101752 KB |
Output is correct |
3 |
Correct |
921 ms |
100468 KB |
Output is correct |
4 |
Correct |
659 ms |
100436 KB |
Output is correct |
5 |
Correct |
496 ms |
97528 KB |
Output is correct |
6 |
Correct |
344 ms |
97756 KB |
Output is correct |
7 |
Correct |
305 ms |
97616 KB |
Output is correct |
8 |
Correct |
261 ms |
98100 KB |
Output is correct |
9 |
Correct |
604 ms |
99556 KB |
Output is correct |
10 |
Correct |
1039 ms |
101004 KB |
Output is correct |
11 |
Correct |
488 ms |
97264 KB |
Output is correct |
12 |
Correct |
688 ms |
96744 KB |
Output is correct |
13 |
Correct |
408 ms |
98380 KB |
Output is correct |
14 |
Correct |
416 ms |
99180 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6544 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
668 ms |
104500 KB |
Output is correct |
3 |
Correct |
1051 ms |
101904 KB |
Output is correct |
4 |
Correct |
587 ms |
102932 KB |
Output is correct |
5 |
Correct |
474 ms |
101124 KB |
Output is correct |
6 |
Correct |
394 ms |
102176 KB |
Output is correct |
7 |
Correct |
323 ms |
102740 KB |
Output is correct |
8 |
Correct |
254 ms |
102948 KB |
Output is correct |
9 |
Correct |
639 ms |
107212 KB |
Output is correct |
10 |
Correct |
913 ms |
105804 KB |
Output is correct |
11 |
Correct |
496 ms |
103512 KB |
Output is correct |
12 |
Correct |
563 ms |
102100 KB |
Output is correct |
13 |
Correct |
392 ms |
102780 KB |
Output is correct |
14 |
Correct |
407 ms |
103748 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6544 KB |
Output is correct |
18 |
Correct |
2 ms |
6488 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6452 KB |
Output is correct |
4 |
Correct |
3 ms |
7004 KB |
Output is correct |
5 |
Correct |
3 ms |
6812 KB |
Output is correct |
6 |
Correct |
3 ms |
7004 KB |
Output is correct |
7 |
Correct |
3 ms |
7004 KB |
Output is correct |
8 |
Correct |
4 ms |
7004 KB |
Output is correct |
9 |
Correct |
3 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6552 KB |
Output is correct |
18 |
Correct |
3 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6496 KB |
Output is correct |
23 |
Correct |
2 ms |
6548 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6488 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6544 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6492 KB |
Output is correct |
30 |
Correct |
536 ms |
100332 KB |
Output is correct |
31 |
Correct |
373 ms |
99016 KB |
Output is correct |
32 |
Correct |
533 ms |
101872 KB |
Output is correct |
33 |
Correct |
391 ms |
99476 KB |
Output is correct |
34 |
Correct |
340 ms |
99516 KB |
Output is correct |
35 |
Correct |
347 ms |
99920 KB |
Output is correct |
36 |
Correct |
267 ms |
99928 KB |
Output is correct |
37 |
Correct |
616 ms |
104052 KB |
Output is correct |
38 |
Correct |
386 ms |
102676 KB |
Output is correct |
39 |
Correct |
551 ms |
100664 KB |
Output is correct |
40 |
Correct |
404 ms |
99052 KB |
Output is correct |
41 |
Correct |
215 ms |
99420 KB |
Output is correct |
42 |
Correct |
202 ms |
99176 KB |
Output is correct |
43 |
Correct |
207 ms |
98644 KB |
Output is correct |
44 |
Correct |
207 ms |
99116 KB |
Output is correct |
45 |
Correct |
221 ms |
99532 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
3 ms |
6748 KB |
Output is correct |
48 |
Correct |
3 ms |
6492 KB |
Output is correct |
49 |
Correct |
3 ms |
6808 KB |
Output is correct |
50 |
Correct |
2 ms |
6492 KB |
Output is correct |
51 |
Correct |
2 ms |
6548 KB |
Output is correct |
52 |
Correct |
445 ms |
100028 KB |
Output is correct |
53 |
Correct |
335 ms |
98824 KB |
Output is correct |
54 |
Correct |
458 ms |
103252 KB |
Output is correct |
55 |
Correct |
392 ms |
99496 KB |
Output is correct |
56 |
Correct |
296 ms |
99732 KB |
Output is correct |
57 |
Correct |
312 ms |
99540 KB |
Output is correct |
58 |
Correct |
254 ms |
99996 KB |
Output is correct |
59 |
Correct |
613 ms |
102776 KB |
Output is correct |
60 |
Correct |
343 ms |
102428 KB |
Output is correct |
61 |
Correct |
497 ms |
100152 KB |
Output is correct |
62 |
Correct |
324 ms |
98896 KB |
Output is correct |
63 |
Correct |
2 ms |
6488 KB |
Output is correct |
64 |
Correct |
2 ms |
6492 KB |
Output is correct |
65 |
Correct |
2 ms |
6492 KB |
Output is correct |
66 |
Correct |
2 ms |
6492 KB |
Output is correct |
67 |
Correct |
2 ms |
6492 KB |
Output is correct |
68 |
Correct |
2 ms |
6544 KB |
Output is correct |
69 |
Correct |
2 ms |
6492 KB |
Output is correct |
70 |
Correct |
2 ms |
6492 KB |
Output is correct |
71 |
Correct |
2 ms |
6492 KB |
Output is correct |
72 |
Correct |
2 ms |
6492 KB |
Output is correct |
73 |
Correct |
2 ms |
6492 KB |
Output is correct |
74 |
Correct |
2 ms |
6492 KB |
Output is correct |
75 |
Correct |
2 ms |
6492 KB |
Output is correct |
76 |
Correct |
2 ms |
6492 KB |
Output is correct |
77 |
Correct |
2 ms |
6544 KB |
Output is correct |
78 |
Correct |
2 ms |
6492 KB |
Output is correct |
79 |
Correct |
639 ms |
101752 KB |
Output is correct |
80 |
Correct |
921 ms |
100468 KB |
Output is correct |
81 |
Correct |
659 ms |
100436 KB |
Output is correct |
82 |
Correct |
496 ms |
97528 KB |
Output is correct |
83 |
Correct |
344 ms |
97756 KB |
Output is correct |
84 |
Correct |
305 ms |
97616 KB |
Output is correct |
85 |
Correct |
261 ms |
98100 KB |
Output is correct |
86 |
Correct |
604 ms |
99556 KB |
Output is correct |
87 |
Correct |
1039 ms |
101004 KB |
Output is correct |
88 |
Correct |
488 ms |
97264 KB |
Output is correct |
89 |
Correct |
688 ms |
96744 KB |
Output is correct |
90 |
Correct |
408 ms |
98380 KB |
Output is correct |
91 |
Correct |
416 ms |
99180 KB |
Output is correct |
92 |
Correct |
2 ms |
6744 KB |
Output is correct |
93 |
Correct |
2 ms |
6492 KB |
Output is correct |
94 |
Correct |
2 ms |
6492 KB |
Output is correct |
95 |
Correct |
2 ms |
6544 KB |
Output is correct |
96 |
Correct |
2 ms |
6492 KB |
Output is correct |
97 |
Correct |
2 ms |
6492 KB |
Output is correct |
98 |
Correct |
668 ms |
104500 KB |
Output is correct |
99 |
Correct |
1051 ms |
101904 KB |
Output is correct |
100 |
Correct |
587 ms |
102932 KB |
Output is correct |
101 |
Correct |
474 ms |
101124 KB |
Output is correct |
102 |
Correct |
394 ms |
102176 KB |
Output is correct |
103 |
Correct |
323 ms |
102740 KB |
Output is correct |
104 |
Correct |
254 ms |
102948 KB |
Output is correct |
105 |
Correct |
639 ms |
107212 KB |
Output is correct |
106 |
Correct |
913 ms |
105804 KB |
Output is correct |
107 |
Correct |
496 ms |
103512 KB |
Output is correct |
108 |
Correct |
563 ms |
102100 KB |
Output is correct |
109 |
Correct |
392 ms |
102780 KB |
Output is correct |
110 |
Correct |
407 ms |
103748 KB |
Output is correct |
111 |
Correct |
2 ms |
6492 KB |
Output is correct |
112 |
Correct |
2 ms |
6492 KB |
Output is correct |
113 |
Correct |
2 ms |
6544 KB |
Output is correct |
114 |
Correct |
2 ms |
6488 KB |
Output is correct |
115 |
Correct |
2 ms |
6492 KB |
Output is correct |
116 |
Correct |
512 ms |
101972 KB |
Output is correct |
117 |
Correct |
615 ms |
104640 KB |
Output is correct |
118 |
Correct |
644 ms |
108008 KB |
Output is correct |
119 |
Correct |
513 ms |
104532 KB |
Output is correct |
120 |
Correct |
408 ms |
104020 KB |
Output is correct |
121 |
Correct |
380 ms |
104780 KB |
Output is correct |
122 |
Correct |
273 ms |
104892 KB |
Output is correct |
123 |
Correct |
621 ms |
106964 KB |
Output is correct |
124 |
Correct |
1050 ms |
106216 KB |
Output is correct |
125 |
Correct |
585 ms |
103272 KB |
Output is correct |
126 |
Correct |
799 ms |
104432 KB |
Output is correct |
127 |
Correct |
879 ms |
104980 KB |
Output is correct |
128 |
Correct |
591 ms |
105696 KB |
Output is correct |
129 |
Correct |
566 ms |
106500 KB |
Output is correct |