#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,mod,q;
vector<int> al[200105];
int pp[200105];
int d[200105];
int memo[200105][42];
void dfs(int i,int p){
for (auto it:al[i]){
if (it==p) continue;
d[it]=d[i]+1;
pp[it]=i;
dfs(it,i);
}
}
signed main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n>>mod;
int a,b,c;
rep(x,1,n){
cin>>a>>b;
al[a].pub(b);
al[b].pub(a);
}
int p=1;
int curr=n+1;
rep(x,0,50){
al[p].pub(curr);
al[curr].pub(p);
p=curr;
curr++;
}
pp[p]=-1;
dfs(p,-1);
rep(x,1,p+1) rep(y,0,42) memo[x][y]=1;
rep(x,1,n+1) cin>>memo[x][0];
cin>>q;
while (q--){
cin>>a;
if (a==1){
cin>>a>>b>>c;
rep(x,0,b+1){
memo[a][b-x]=memo[a][b-x]*c%mod;
a=pp[a];
}
}
else{
cin>>a;
int curr=0;
int res=1;
while (curr<41){
res=res*memo[a][curr]%mod;
res=res*memo[a][curr+1]%mod;
a=pp[a];
curr++;
}
cout<<res<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
5 ms |
5460 KB |
Output is correct |
6 |
Correct |
4 ms |
5424 KB |
Output is correct |
7 |
Correct |
5 ms |
5428 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
5 ms |
5076 KB |
Output is correct |
10 |
Correct |
4 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5044 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5032 KB |
Output is correct |
14 |
Correct |
4 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5040 KB |
Output is correct |
16 |
Correct |
4 ms |
5076 KB |
Output is correct |
17 |
Correct |
5 ms |
5076 KB |
Output is correct |
18 |
Correct |
4 ms |
5084 KB |
Output is correct |
19 |
Correct |
4 ms |
5036 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4968 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
636 ms |
92936 KB |
Output is correct |
3 |
Correct |
427 ms |
92844 KB |
Output is correct |
4 |
Correct |
602 ms |
100052 KB |
Output is correct |
5 |
Correct |
561 ms |
92784 KB |
Output is correct |
6 |
Correct |
401 ms |
91100 KB |
Output is correct |
7 |
Correct |
437 ms |
93832 KB |
Output is correct |
8 |
Correct |
382 ms |
90848 KB |
Output is correct |
9 |
Correct |
740 ms |
103876 KB |
Output is correct |
10 |
Correct |
409 ms |
102984 KB |
Output is correct |
11 |
Correct |
675 ms |
91844 KB |
Output is correct |
12 |
Correct |
377 ms |
90536 KB |
Output is correct |
13 |
Correct |
304 ms |
92984 KB |
Output is correct |
14 |
Correct |
252 ms |
93028 KB |
Output is correct |
15 |
Correct |
292 ms |
83508 KB |
Output is correct |
16 |
Correct |
273 ms |
92316 KB |
Output is correct |
17 |
Correct |
306 ms |
89320 KB |
Output is correct |
18 |
Correct |
4 ms |
5076 KB |
Output is correct |
19 |
Correct |
5 ms |
5032 KB |
Output is correct |
20 |
Correct |
3 ms |
5040 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
636 ms |
92936 KB |
Output is correct |
3 |
Correct |
427 ms |
92844 KB |
Output is correct |
4 |
Correct |
602 ms |
100052 KB |
Output is correct |
5 |
Correct |
561 ms |
92784 KB |
Output is correct |
6 |
Correct |
401 ms |
91100 KB |
Output is correct |
7 |
Correct |
437 ms |
93832 KB |
Output is correct |
8 |
Correct |
382 ms |
90848 KB |
Output is correct |
9 |
Correct |
740 ms |
103876 KB |
Output is correct |
10 |
Correct |
409 ms |
102984 KB |
Output is correct |
11 |
Correct |
675 ms |
91844 KB |
Output is correct |
12 |
Correct |
377 ms |
90536 KB |
Output is correct |
13 |
Correct |
304 ms |
92984 KB |
Output is correct |
14 |
Correct |
252 ms |
93028 KB |
Output is correct |
15 |
Correct |
292 ms |
83508 KB |
Output is correct |
16 |
Correct |
273 ms |
92316 KB |
Output is correct |
17 |
Correct |
306 ms |
89320 KB |
Output is correct |
18 |
Correct |
4 ms |
5076 KB |
Output is correct |
19 |
Correct |
5 ms |
5032 KB |
Output is correct |
20 |
Correct |
3 ms |
5040 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5060 KB |
Output is correct |
23 |
Correct |
3 ms |
5016 KB |
Output is correct |
24 |
Correct |
677 ms |
92924 KB |
Output is correct |
25 |
Correct |
411 ms |
92788 KB |
Output is correct |
26 |
Correct |
544 ms |
103536 KB |
Output is correct |
27 |
Correct |
527 ms |
92516 KB |
Output is correct |
28 |
Correct |
447 ms |
93252 KB |
Output is correct |
29 |
Correct |
475 ms |
92980 KB |
Output is correct |
30 |
Correct |
396 ms |
93024 KB |
Output is correct |
31 |
Correct |
847 ms |
100048 KB |
Output is correct |
32 |
Correct |
532 ms |
102412 KB |
Output is correct |
33 |
Correct |
743 ms |
92740 KB |
Output is correct |
34 |
Correct |
494 ms |
92284 KB |
Output is correct |
35 |
Correct |
4 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5036 KB |
Output is correct |
37 |
Correct |
3 ms |
5040 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
5 ms |
5076 KB |
Output is correct |
40 |
Correct |
4 ms |
4948 KB |
Output is correct |
41 |
Correct |
4 ms |
5076 KB |
Output is correct |
42 |
Correct |
3 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
5076 KB |
Output is correct |
44 |
Correct |
5 ms |
4948 KB |
Output is correct |
45 |
Correct |
4 ms |
5032 KB |
Output is correct |
46 |
Correct |
4 ms |
5076 KB |
Output is correct |
47 |
Correct |
4 ms |
5032 KB |
Output is correct |
48 |
Correct |
4 ms |
5032 KB |
Output is correct |
49 |
Correct |
4 ms |
5032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5032 KB |
Output is correct |
2 |
Correct |
984 ms |
100232 KB |
Output is correct |
3 |
Correct |
994 ms |
97856 KB |
Output is correct |
4 |
Correct |
905 ms |
98128 KB |
Output is correct |
5 |
Correct |
712 ms |
89776 KB |
Output is correct |
6 |
Correct |
544 ms |
89656 KB |
Output is correct |
7 |
Correct |
465 ms |
90028 KB |
Output is correct |
8 |
Correct |
414 ms |
90160 KB |
Output is correct |
9 |
Correct |
1020 ms |
97272 KB |
Output is correct |
10 |
Correct |
917 ms |
99856 KB |
Output is correct |
11 |
Correct |
857 ms |
89508 KB |
Output is correct |
12 |
Correct |
879 ms |
90096 KB |
Output is correct |
13 |
Correct |
509 ms |
90696 KB |
Output is correct |
14 |
Correct |
541 ms |
92144 KB |
Output is correct |
15 |
Correct |
5 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
5020 KB |
Output is correct |
18 |
Correct |
4 ms |
5036 KB |
Output is correct |
19 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
975 ms |
98632 KB |
Output is correct |
3 |
Correct |
931 ms |
95728 KB |
Output is correct |
4 |
Correct |
796 ms |
97476 KB |
Output is correct |
5 |
Correct |
795 ms |
91348 KB |
Output is correct |
6 |
Correct |
533 ms |
91420 KB |
Output is correct |
7 |
Correct |
551 ms |
91260 KB |
Output is correct |
8 |
Correct |
462 ms |
91428 KB |
Output is correct |
9 |
Correct |
846 ms |
102508 KB |
Output is correct |
10 |
Correct |
753 ms |
100536 KB |
Output is correct |
11 |
Correct |
673 ms |
92076 KB |
Output is correct |
12 |
Correct |
684 ms |
90484 KB |
Output is correct |
13 |
Correct |
474 ms |
91496 KB |
Output is correct |
14 |
Correct |
476 ms |
92444 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5064 KB |
Output is correct |
18 |
Correct |
3 ms |
5040 KB |
Output is correct |
19 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
5 ms |
5460 KB |
Output is correct |
6 |
Correct |
4 ms |
5424 KB |
Output is correct |
7 |
Correct |
5 ms |
5428 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
5 ms |
5076 KB |
Output is correct |
10 |
Correct |
4 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5044 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5032 KB |
Output is correct |
14 |
Correct |
4 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5040 KB |
Output is correct |
16 |
Correct |
4 ms |
5076 KB |
Output is correct |
17 |
Correct |
5 ms |
5076 KB |
Output is correct |
18 |
Correct |
4 ms |
5084 KB |
Output is correct |
19 |
Correct |
4 ms |
5036 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4968 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5032 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
636 ms |
92936 KB |
Output is correct |
31 |
Correct |
427 ms |
92844 KB |
Output is correct |
32 |
Correct |
602 ms |
100052 KB |
Output is correct |
33 |
Correct |
561 ms |
92784 KB |
Output is correct |
34 |
Correct |
401 ms |
91100 KB |
Output is correct |
35 |
Correct |
437 ms |
93832 KB |
Output is correct |
36 |
Correct |
382 ms |
90848 KB |
Output is correct |
37 |
Correct |
740 ms |
103876 KB |
Output is correct |
38 |
Correct |
409 ms |
102984 KB |
Output is correct |
39 |
Correct |
675 ms |
91844 KB |
Output is correct |
40 |
Correct |
377 ms |
90536 KB |
Output is correct |
41 |
Correct |
304 ms |
92984 KB |
Output is correct |
42 |
Correct |
252 ms |
93028 KB |
Output is correct |
43 |
Correct |
292 ms |
83508 KB |
Output is correct |
44 |
Correct |
273 ms |
92316 KB |
Output is correct |
45 |
Correct |
306 ms |
89320 KB |
Output is correct |
46 |
Correct |
4 ms |
5076 KB |
Output is correct |
47 |
Correct |
5 ms |
5032 KB |
Output is correct |
48 |
Correct |
3 ms |
5040 KB |
Output is correct |
49 |
Correct |
3 ms |
5076 KB |
Output is correct |
50 |
Correct |
4 ms |
5060 KB |
Output is correct |
51 |
Correct |
3 ms |
5016 KB |
Output is correct |
52 |
Correct |
677 ms |
92924 KB |
Output is correct |
53 |
Correct |
411 ms |
92788 KB |
Output is correct |
54 |
Correct |
544 ms |
103536 KB |
Output is correct |
55 |
Correct |
527 ms |
92516 KB |
Output is correct |
56 |
Correct |
447 ms |
93252 KB |
Output is correct |
57 |
Correct |
475 ms |
92980 KB |
Output is correct |
58 |
Correct |
396 ms |
93024 KB |
Output is correct |
59 |
Correct |
847 ms |
100048 KB |
Output is correct |
60 |
Correct |
532 ms |
102412 KB |
Output is correct |
61 |
Correct |
743 ms |
92740 KB |
Output is correct |
62 |
Correct |
494 ms |
92284 KB |
Output is correct |
63 |
Correct |
4 ms |
5076 KB |
Output is correct |
64 |
Correct |
4 ms |
5036 KB |
Output is correct |
65 |
Correct |
3 ms |
5040 KB |
Output is correct |
66 |
Correct |
4 ms |
5076 KB |
Output is correct |
67 |
Correct |
5 ms |
5076 KB |
Output is correct |
68 |
Correct |
4 ms |
4948 KB |
Output is correct |
69 |
Correct |
4 ms |
5076 KB |
Output is correct |
70 |
Correct |
3 ms |
5076 KB |
Output is correct |
71 |
Correct |
4 ms |
5076 KB |
Output is correct |
72 |
Correct |
5 ms |
4948 KB |
Output is correct |
73 |
Correct |
4 ms |
5032 KB |
Output is correct |
74 |
Correct |
4 ms |
5076 KB |
Output is correct |
75 |
Correct |
4 ms |
5032 KB |
Output is correct |
76 |
Correct |
4 ms |
5032 KB |
Output is correct |
77 |
Correct |
4 ms |
5032 KB |
Output is correct |
78 |
Correct |
4 ms |
5032 KB |
Output is correct |
79 |
Correct |
984 ms |
100232 KB |
Output is correct |
80 |
Correct |
994 ms |
97856 KB |
Output is correct |
81 |
Correct |
905 ms |
98128 KB |
Output is correct |
82 |
Correct |
712 ms |
89776 KB |
Output is correct |
83 |
Correct |
544 ms |
89656 KB |
Output is correct |
84 |
Correct |
465 ms |
90028 KB |
Output is correct |
85 |
Correct |
414 ms |
90160 KB |
Output is correct |
86 |
Correct |
1020 ms |
97272 KB |
Output is correct |
87 |
Correct |
917 ms |
99856 KB |
Output is correct |
88 |
Correct |
857 ms |
89508 KB |
Output is correct |
89 |
Correct |
879 ms |
90096 KB |
Output is correct |
90 |
Correct |
509 ms |
90696 KB |
Output is correct |
91 |
Correct |
541 ms |
92144 KB |
Output is correct |
92 |
Correct |
5 ms |
4948 KB |
Output is correct |
93 |
Correct |
4 ms |
4948 KB |
Output is correct |
94 |
Correct |
4 ms |
5020 KB |
Output is correct |
95 |
Correct |
4 ms |
5036 KB |
Output is correct |
96 |
Correct |
4 ms |
5076 KB |
Output is correct |
97 |
Correct |
3 ms |
4948 KB |
Output is correct |
98 |
Correct |
975 ms |
98632 KB |
Output is correct |
99 |
Correct |
931 ms |
95728 KB |
Output is correct |
100 |
Correct |
796 ms |
97476 KB |
Output is correct |
101 |
Correct |
795 ms |
91348 KB |
Output is correct |
102 |
Correct |
533 ms |
91420 KB |
Output is correct |
103 |
Correct |
551 ms |
91260 KB |
Output is correct |
104 |
Correct |
462 ms |
91428 KB |
Output is correct |
105 |
Correct |
846 ms |
102508 KB |
Output is correct |
106 |
Correct |
753 ms |
100536 KB |
Output is correct |
107 |
Correct |
673 ms |
92076 KB |
Output is correct |
108 |
Correct |
684 ms |
90484 KB |
Output is correct |
109 |
Correct |
474 ms |
91496 KB |
Output is correct |
110 |
Correct |
476 ms |
92444 KB |
Output is correct |
111 |
Correct |
3 ms |
5076 KB |
Output is correct |
112 |
Correct |
3 ms |
5076 KB |
Output is correct |
113 |
Correct |
3 ms |
5064 KB |
Output is correct |
114 |
Correct |
3 ms |
5040 KB |
Output is correct |
115 |
Correct |
4 ms |
5076 KB |
Output is correct |
116 |
Correct |
775 ms |
90516 KB |
Output is correct |
117 |
Correct |
733 ms |
92852 KB |
Output is correct |
118 |
Correct |
706 ms |
102744 KB |
Output is correct |
119 |
Correct |
677 ms |
92504 KB |
Output is correct |
120 |
Correct |
559 ms |
92072 KB |
Output is correct |
121 |
Correct |
533 ms |
92796 KB |
Output is correct |
122 |
Correct |
434 ms |
93024 KB |
Output is correct |
123 |
Correct |
792 ms |
101244 KB |
Output is correct |
124 |
Correct |
818 ms |
98588 KB |
Output is correct |
125 |
Correct |
777 ms |
91216 KB |
Output is correct |
126 |
Correct |
785 ms |
92004 KB |
Output is correct |
127 |
Correct |
746 ms |
92652 KB |
Output is correct |
128 |
Correct |
505 ms |
92352 KB |
Output is correct |
129 |
Correct |
526 ms |
94160 KB |
Output is correct |