#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const long long siz=225000;
long long a[siz],p[siz];
long long up[siz][45];
vector<long long> adj[200001];
void dfs(long long x, long long par) {
for (auto xd:adj[x]){
if (xd==par){
continue;
}
dfs(xd , x);
p[xd]=x;
}
}
int main(){
ios::sync_with_stdio(false);
long long n, md;
cin>>n>>md;
for (long long i=1; i<n; i++) {
long long x,y;
cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
}
for (long long i=1; i<=n; i++) {
cin>>a[i];
}
p[1]=n+1;
for (long long i=1; i<=n+45; i++) {
for (long long j=0; j<=40; j++) {
up[i][j] = 1;
if(i>=n+1){
p[i]=i+1;
}
}
}
dfs(1,1);
long long q;
cin>>q;
while(q--){
long long temp;
cin>>temp;
if (temp==1) {
long long x, dis, w;
cin>>x>>dis>>w;
while (dis>=0) {
// cout<<"x"<<x<<" up"<<up[x][dis]<<endl;
up[x][dis]=(w*up[x][dis])%md;
if(dis>0){
up[x][dis-1]=(w*up[x][dis-1])%md;
}
x=p[x];
// cout<<dis<<endl;
dis--;
}
}else {
//cout<<" "<<pas<<" br"<<" meore"<<endl;
long long x;
long long pas=1;
cin>>x;
pas=a[x];
long long j=0;
while (j<=40) {
pas=(pas*(up[x][j])%md)%md;
j++;
x=p[x];
}
cout<<pas<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5460 KB |
Output is correct |
5 |
Correct |
4 ms |
5432 KB |
Output is correct |
6 |
Correct |
4 ms |
5420 KB |
Output is correct |
7 |
Correct |
5 ms |
5460 KB |
Output is correct |
8 |
Correct |
5 ms |
5484 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5040 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
5076 KB |
Output is correct |
17 |
Correct |
4 ms |
5028 KB |
Output is correct |
18 |
Correct |
4 ms |
5076 KB |
Output is correct |
19 |
Correct |
5 ms |
5076 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
5 ms |
5032 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
4 ms |
5036 KB |
Output is correct |
25 |
Correct |
4 ms |
4948 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
4948 KB |
Output is correct |
28 |
Correct |
4 ms |
5032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
998 ms |
89476 KB |
Output is correct |
3 |
Correct |
421 ms |
86416 KB |
Output is correct |
4 |
Correct |
767 ms |
90620 KB |
Output is correct |
5 |
Correct |
696 ms |
87932 KB |
Output is correct |
6 |
Correct |
604 ms |
87852 KB |
Output is correct |
7 |
Correct |
589 ms |
88204 KB |
Output is correct |
8 |
Correct |
532 ms |
88504 KB |
Output is correct |
9 |
Correct |
1054 ms |
94088 KB |
Output is correct |
10 |
Correct |
440 ms |
90500 KB |
Output is correct |
11 |
Correct |
1050 ms |
89528 KB |
Output is correct |
12 |
Correct |
440 ms |
86456 KB |
Output is correct |
13 |
Correct |
303 ms |
86684 KB |
Output is correct |
14 |
Correct |
311 ms |
86776 KB |
Output is correct |
15 |
Correct |
316 ms |
86532 KB |
Output is correct |
16 |
Correct |
328 ms |
86600 KB |
Output is correct |
17 |
Correct |
316 ms |
87164 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 |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
998 ms |
89476 KB |
Output is correct |
3 |
Correct |
421 ms |
86416 KB |
Output is correct |
4 |
Correct |
767 ms |
90620 KB |
Output is correct |
5 |
Correct |
696 ms |
87932 KB |
Output is correct |
6 |
Correct |
604 ms |
87852 KB |
Output is correct |
7 |
Correct |
589 ms |
88204 KB |
Output is correct |
8 |
Correct |
532 ms |
88504 KB |
Output is correct |
9 |
Correct |
1054 ms |
94088 KB |
Output is correct |
10 |
Correct |
440 ms |
90500 KB |
Output is correct |
11 |
Correct |
1050 ms |
89528 KB |
Output is correct |
12 |
Correct |
440 ms |
86456 KB |
Output is correct |
13 |
Correct |
303 ms |
86684 KB |
Output is correct |
14 |
Correct |
311 ms |
86776 KB |
Output is correct |
15 |
Correct |
316 ms |
86532 KB |
Output is correct |
16 |
Correct |
328 ms |
86600 KB |
Output is correct |
17 |
Correct |
316 ms |
87164 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 |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
4964 KB |
Output is correct |
24 |
Correct |
1016 ms |
89532 KB |
Output is correct |
25 |
Correct |
475 ms |
86308 KB |
Output is correct |
26 |
Correct |
766 ms |
92388 KB |
Output is correct |
27 |
Correct |
766 ms |
87820 KB |
Output is correct |
28 |
Correct |
605 ms |
88028 KB |
Output is correct |
29 |
Correct |
606 ms |
88220 KB |
Output is correct |
30 |
Correct |
529 ms |
88464 KB |
Output is correct |
31 |
Correct |
1070 ms |
92500 KB |
Output is correct |
32 |
Correct |
479 ms |
90552 KB |
Output is correct |
33 |
Correct |
994 ms |
89444 KB |
Output is correct |
34 |
Correct |
445 ms |
86236 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
4 ms |
5036 KB |
Output is correct |
37 |
Correct |
4 ms |
5064 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
4 ms |
5076 KB |
Output is correct |
40 |
Correct |
5 ms |
4948 KB |
Output is correct |
41 |
Correct |
4 ms |
5032 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
4948 KB |
Output is correct |
44 |
Correct |
4 ms |
4976 KB |
Output is correct |
45 |
Correct |
4 ms |
4988 KB |
Output is correct |
46 |
Correct |
4 ms |
4948 KB |
Output is correct |
47 |
Correct |
4 ms |
4948 KB |
Output is correct |
48 |
Correct |
4 ms |
5076 KB |
Output is correct |
49 |
Correct |
4 ms |
5036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
1064 ms |
91436 KB |
Output is correct |
3 |
Correct |
882 ms |
98724 KB |
Output is correct |
4 |
Correct |
867 ms |
98436 KB |
Output is correct |
5 |
Correct |
803 ms |
94976 KB |
Output is correct |
6 |
Correct |
635 ms |
95228 KB |
Output is correct |
7 |
Correct |
657 ms |
95232 KB |
Output is correct |
8 |
Correct |
564 ms |
95540 KB |
Output is correct |
9 |
Correct |
1085 ms |
97752 KB |
Output is correct |
10 |
Correct |
839 ms |
99652 KB |
Output is correct |
11 |
Correct |
1048 ms |
94592 KB |
Output is correct |
12 |
Correct |
775 ms |
95544 KB |
Output is correct |
13 |
Correct |
471 ms |
96336 KB |
Output is correct |
14 |
Correct |
467 ms |
97364 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
5 ms |
4952 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5036 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
1078 ms |
100140 KB |
Output is correct |
3 |
Correct |
809 ms |
97708 KB |
Output is correct |
4 |
Correct |
834 ms |
98920 KB |
Output is correct |
5 |
Correct |
824 ms |
96484 KB |
Output is correct |
6 |
Correct |
662 ms |
96788 KB |
Output is correct |
7 |
Correct |
644 ms |
96548 KB |
Output is correct |
8 |
Correct |
573 ms |
96508 KB |
Output is correct |
9 |
Correct |
1111 ms |
101672 KB |
Output is correct |
10 |
Correct |
813 ms |
100044 KB |
Output is correct |
11 |
Correct |
1069 ms |
97404 KB |
Output is correct |
12 |
Correct |
752 ms |
96064 KB |
Output is correct |
13 |
Correct |
488 ms |
96628 KB |
Output is correct |
14 |
Correct |
542 ms |
97408 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5036 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5460 KB |
Output is correct |
5 |
Correct |
4 ms |
5432 KB |
Output is correct |
6 |
Correct |
4 ms |
5420 KB |
Output is correct |
7 |
Correct |
5 ms |
5460 KB |
Output is correct |
8 |
Correct |
5 ms |
5484 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5040 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
5076 KB |
Output is correct |
17 |
Correct |
4 ms |
5028 KB |
Output is correct |
18 |
Correct |
4 ms |
5076 KB |
Output is correct |
19 |
Correct |
5 ms |
5076 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
5 ms |
5032 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
4 ms |
5036 KB |
Output is correct |
25 |
Correct |
4 ms |
4948 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
4948 KB |
Output is correct |
28 |
Correct |
4 ms |
5032 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
998 ms |
89476 KB |
Output is correct |
31 |
Correct |
421 ms |
86416 KB |
Output is correct |
32 |
Correct |
767 ms |
90620 KB |
Output is correct |
33 |
Correct |
696 ms |
87932 KB |
Output is correct |
34 |
Correct |
604 ms |
87852 KB |
Output is correct |
35 |
Correct |
589 ms |
88204 KB |
Output is correct |
36 |
Correct |
532 ms |
88504 KB |
Output is correct |
37 |
Correct |
1054 ms |
94088 KB |
Output is correct |
38 |
Correct |
440 ms |
90500 KB |
Output is correct |
39 |
Correct |
1050 ms |
89528 KB |
Output is correct |
40 |
Correct |
440 ms |
86456 KB |
Output is correct |
41 |
Correct |
303 ms |
86684 KB |
Output is correct |
42 |
Correct |
311 ms |
86776 KB |
Output is correct |
43 |
Correct |
316 ms |
86532 KB |
Output is correct |
44 |
Correct |
328 ms |
86600 KB |
Output is correct |
45 |
Correct |
316 ms |
87164 KB |
Output is correct |
46 |
Correct |
4 ms |
4948 KB |
Output is correct |
47 |
Correct |
3 ms |
4948 KB |
Output is correct |
48 |
Correct |
3 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
3 ms |
4948 KB |
Output is correct |
51 |
Correct |
3 ms |
4964 KB |
Output is correct |
52 |
Correct |
1016 ms |
89532 KB |
Output is correct |
53 |
Correct |
475 ms |
86308 KB |
Output is correct |
54 |
Correct |
766 ms |
92388 KB |
Output is correct |
55 |
Correct |
766 ms |
87820 KB |
Output is correct |
56 |
Correct |
605 ms |
88028 KB |
Output is correct |
57 |
Correct |
606 ms |
88220 KB |
Output is correct |
58 |
Correct |
529 ms |
88464 KB |
Output is correct |
59 |
Correct |
1070 ms |
92500 KB |
Output is correct |
60 |
Correct |
479 ms |
90552 KB |
Output is correct |
61 |
Correct |
994 ms |
89444 KB |
Output is correct |
62 |
Correct |
445 ms |
86236 KB |
Output is correct |
63 |
Correct |
3 ms |
4948 KB |
Output is correct |
64 |
Correct |
4 ms |
5036 KB |
Output is correct |
65 |
Correct |
4 ms |
5064 KB |
Output is correct |
66 |
Correct |
4 ms |
5076 KB |
Output is correct |
67 |
Correct |
4 ms |
5076 KB |
Output is correct |
68 |
Correct |
5 ms |
4948 KB |
Output is correct |
69 |
Correct |
4 ms |
5032 KB |
Output is correct |
70 |
Correct |
4 ms |
5076 KB |
Output is correct |
71 |
Correct |
4 ms |
4948 KB |
Output is correct |
72 |
Correct |
4 ms |
4976 KB |
Output is correct |
73 |
Correct |
4 ms |
4988 KB |
Output is correct |
74 |
Correct |
4 ms |
4948 KB |
Output is correct |
75 |
Correct |
4 ms |
4948 KB |
Output is correct |
76 |
Correct |
4 ms |
5076 KB |
Output is correct |
77 |
Correct |
4 ms |
5036 KB |
Output is correct |
78 |
Correct |
2 ms |
4948 KB |
Output is correct |
79 |
Correct |
1064 ms |
91436 KB |
Output is correct |
80 |
Correct |
882 ms |
98724 KB |
Output is correct |
81 |
Correct |
867 ms |
98436 KB |
Output is correct |
82 |
Correct |
803 ms |
94976 KB |
Output is correct |
83 |
Correct |
635 ms |
95228 KB |
Output is correct |
84 |
Correct |
657 ms |
95232 KB |
Output is correct |
85 |
Correct |
564 ms |
95540 KB |
Output is correct |
86 |
Correct |
1085 ms |
97752 KB |
Output is correct |
87 |
Correct |
839 ms |
99652 KB |
Output is correct |
88 |
Correct |
1048 ms |
94592 KB |
Output is correct |
89 |
Correct |
775 ms |
95544 KB |
Output is correct |
90 |
Correct |
471 ms |
96336 KB |
Output is correct |
91 |
Correct |
467 ms |
97364 KB |
Output is correct |
92 |
Correct |
4 ms |
4948 KB |
Output is correct |
93 |
Correct |
5 ms |
4952 KB |
Output is correct |
94 |
Correct |
4 ms |
4948 KB |
Output is correct |
95 |
Correct |
3 ms |
5036 KB |
Output is correct |
96 |
Correct |
4 ms |
4948 KB |
Output is correct |
97 |
Correct |
3 ms |
4948 KB |
Output is correct |
98 |
Correct |
1078 ms |
100140 KB |
Output is correct |
99 |
Correct |
809 ms |
97708 KB |
Output is correct |
100 |
Correct |
834 ms |
98920 KB |
Output is correct |
101 |
Correct |
824 ms |
96484 KB |
Output is correct |
102 |
Correct |
662 ms |
96788 KB |
Output is correct |
103 |
Correct |
644 ms |
96548 KB |
Output is correct |
104 |
Correct |
573 ms |
96508 KB |
Output is correct |
105 |
Correct |
1111 ms |
101672 KB |
Output is correct |
106 |
Correct |
813 ms |
100044 KB |
Output is correct |
107 |
Correct |
1069 ms |
97404 KB |
Output is correct |
108 |
Correct |
752 ms |
96064 KB |
Output is correct |
109 |
Correct |
488 ms |
96628 KB |
Output is correct |
110 |
Correct |
542 ms |
97408 KB |
Output is correct |
111 |
Correct |
4 ms |
4948 KB |
Output is correct |
112 |
Correct |
4 ms |
5076 KB |
Output is correct |
113 |
Correct |
3 ms |
5036 KB |
Output is correct |
114 |
Correct |
4 ms |
4948 KB |
Output is correct |
115 |
Correct |
4 ms |
5048 KB |
Output is correct |
116 |
Correct |
1118 ms |
95744 KB |
Output is correct |
117 |
Correct |
831 ms |
98268 KB |
Output is correct |
118 |
Correct |
945 ms |
102516 KB |
Output is correct |
119 |
Correct |
909 ms |
98064 KB |
Output is correct |
120 |
Correct |
739 ms |
97720 KB |
Output is correct |
121 |
Correct |
736 ms |
98556 KB |
Output is correct |
122 |
Correct |
637 ms |
98604 KB |
Output is correct |
123 |
Correct |
1195 ms |
101336 KB |
Output is correct |
124 |
Correct |
929 ms |
100544 KB |
Output is correct |
125 |
Correct |
1252 ms |
96832 KB |
Output is correct |
126 |
Correct |
860 ms |
98460 KB |
Output is correct |
127 |
Correct |
802 ms |
98656 KB |
Output is correct |
128 |
Correct |
611 ms |
99368 KB |
Output is correct |
129 |
Correct |
647 ms |
100408 KB |
Output is correct |