#include <bits/stdc++.h>
#define se second
#define fs first
#define pb push_back
#define ll long long
#define ii pair<ll,ll>
#define ld long double
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }
const int N = 2e5 + 7;
ll Mod = 1e9 + 7;
const int szBL = 916;
const ll INF = 1e9;
const int BASE = 137;
int n, Q;
ll a[N];
ll val[N][45], par[N][45];
vector<int> ke[N];
void dfs (int u, int p){
par[u][1] = p;
par[u][0] = u;
rep (i, 2, 40) par[u][i] = par[par[u][i - 1]][1];
iter (&v, ke[u]) {
if (v != p) dfs (v, u);
}
}
void update (int u, int d, ll w) {
rep (i, 0, d) {
if (par[u][i] == 0) {
reb (j, d - i, 0) (val[0][j] *= w) %= Mod;
return;
}
rep (j, d - i - 1, d - i) (val[par[u][i]][j] *= w) %= Mod;
}
}
ll get (int x, int de) {
if (x == 0 || de == 41) return val[x][de];
return val[x][de] * get (par[x][1], de + 1) % Mod;
}
void solution () {
cin >> n >> Mod;
rep (i, 1, n - 1) {
int u, v;
cin >> u >> v;
ke[u].push_back(v);
ke[v].push_back(u);
}
rep (i, 0, n) rep (j, 0, 41) val[i][j] = 1;
rep (i, 1, n) cin >> a[i], val[i][0] = a[i];
dfs (1, 0);
cin >> Q;
rep (i, 1, Q) {
int typ; cin >> typ;
if (typ == 1) {
ll x, d, w;
cin >>x >> d >> w;
update (x, d, w);
}
else {
ll x;
cin >> x;
cout << get (x, 0) <<"\n";
}
}
}
#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
int main () {
// file("c");
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll num_Test = 1;
// cin >> num_Test;
while(num_Test--)
solution();
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
4 ms |
5720 KB |
Output is correct |
5 |
Correct |
4 ms |
5724 KB |
Output is correct |
6 |
Correct |
3 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
5724 KB |
Output is correct |
8 |
Correct |
3 ms |
5720 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5060 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1035 ms |
165548 KB |
Output is correct |
3 |
Correct |
469 ms |
166208 KB |
Output is correct |
4 |
Correct |
977 ms |
171700 KB |
Output is correct |
5 |
Correct |
749 ms |
165992 KB |
Output is correct |
6 |
Correct |
446 ms |
165504 KB |
Output is correct |
7 |
Correct |
410 ms |
166224 KB |
Output is correct |
8 |
Correct |
317 ms |
166604 KB |
Output is correct |
9 |
Correct |
1367 ms |
174604 KB |
Output is correct |
10 |
Correct |
545 ms |
174160 KB |
Output is correct |
11 |
Correct |
1010 ms |
165724 KB |
Output is correct |
12 |
Correct |
490 ms |
166228 KB |
Output is correct |
13 |
Correct |
258 ms |
166336 KB |
Output is correct |
14 |
Correct |
260 ms |
166848 KB |
Output is correct |
15 |
Correct |
266 ms |
166228 KB |
Output is correct |
16 |
Correct |
273 ms |
167000 KB |
Output is correct |
17 |
Correct |
320 ms |
167248 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4952 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5212 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1035 ms |
165548 KB |
Output is correct |
3 |
Correct |
469 ms |
166208 KB |
Output is correct |
4 |
Correct |
977 ms |
171700 KB |
Output is correct |
5 |
Correct |
749 ms |
165992 KB |
Output is correct |
6 |
Correct |
446 ms |
165504 KB |
Output is correct |
7 |
Correct |
410 ms |
166224 KB |
Output is correct |
8 |
Correct |
317 ms |
166604 KB |
Output is correct |
9 |
Correct |
1367 ms |
174604 KB |
Output is correct |
10 |
Correct |
545 ms |
174160 KB |
Output is correct |
11 |
Correct |
1010 ms |
165724 KB |
Output is correct |
12 |
Correct |
490 ms |
166228 KB |
Output is correct |
13 |
Correct |
258 ms |
166336 KB |
Output is correct |
14 |
Correct |
260 ms |
166848 KB |
Output is correct |
15 |
Correct |
266 ms |
166228 KB |
Output is correct |
16 |
Correct |
273 ms |
167000 KB |
Output is correct |
17 |
Correct |
320 ms |
167248 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4952 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5212 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
4 ms |
4952 KB |
Output is correct |
24 |
Correct |
1046 ms |
165612 KB |
Output is correct |
25 |
Correct |
459 ms |
166228 KB |
Output is correct |
26 |
Correct |
973 ms |
174420 KB |
Output is correct |
27 |
Correct |
723 ms |
165912 KB |
Output is correct |
28 |
Correct |
420 ms |
165972 KB |
Output is correct |
29 |
Correct |
404 ms |
155860 KB |
Output is correct |
30 |
Correct |
312 ms |
164804 KB |
Output is correct |
31 |
Correct |
1460 ms |
170916 KB |
Output is correct |
32 |
Correct |
602 ms |
172112 KB |
Output is correct |
33 |
Correct |
1032 ms |
160480 KB |
Output is correct |
34 |
Correct |
468 ms |
154716 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
2 ms |
5212 KB |
Output is correct |
39 |
Correct |
3 ms |
4956 KB |
Output is correct |
40 |
Correct |
2 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
4960 KB |
Output is correct |
44 |
Correct |
3 ms |
4956 KB |
Output is correct |
45 |
Correct |
2 ms |
4956 KB |
Output is correct |
46 |
Correct |
3 ms |
4956 KB |
Output is correct |
47 |
Correct |
3 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
3 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1421 ms |
163660 KB |
Output is correct |
3 |
Correct |
880 ms |
170444 KB |
Output is correct |
4 |
Correct |
1258 ms |
169916 KB |
Output is correct |
5 |
Correct |
803 ms |
162848 KB |
Output is correct |
6 |
Correct |
482 ms |
162900 KB |
Output is correct |
7 |
Correct |
459 ms |
163292 KB |
Output is correct |
8 |
Correct |
319 ms |
163780 KB |
Output is correct |
9 |
Correct |
1518 ms |
168940 KB |
Output is correct |
10 |
Correct |
873 ms |
171440 KB |
Output is correct |
11 |
Correct |
1051 ms |
162640 KB |
Output is correct |
12 |
Correct |
571 ms |
163572 KB |
Output is correct |
13 |
Correct |
465 ms |
164236 KB |
Output is correct |
14 |
Correct |
504 ms |
164892 KB |
Output is correct |
15 |
Correct |
2 ms |
4952 KB |
Output is correct |
16 |
Correct |
2 ms |
4952 KB |
Output is correct |
17 |
Correct |
2 ms |
4996 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
5196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1408 ms |
167560 KB |
Output is correct |
3 |
Correct |
871 ms |
166056 KB |
Output is correct |
4 |
Correct |
1141 ms |
169808 KB |
Output is correct |
5 |
Correct |
762 ms |
164440 KB |
Output is correct |
6 |
Correct |
444 ms |
164736 KB |
Output is correct |
7 |
Correct |
413 ms |
164436 KB |
Output is correct |
8 |
Correct |
305 ms |
164808 KB |
Output is correct |
9 |
Correct |
1473 ms |
173600 KB |
Output is correct |
10 |
Correct |
875 ms |
172036 KB |
Output is correct |
11 |
Correct |
988 ms |
165204 KB |
Output is correct |
12 |
Correct |
533 ms |
163664 KB |
Output is correct |
13 |
Correct |
447 ms |
164432 KB |
Output is correct |
14 |
Correct |
443 ms |
165044 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
5172 KB |
Output is correct |
19 |
Correct |
2 ms |
5168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
4 ms |
5720 KB |
Output is correct |
5 |
Correct |
4 ms |
5724 KB |
Output is correct |
6 |
Correct |
3 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
5724 KB |
Output is correct |
8 |
Correct |
3 ms |
5720 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5060 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
1035 ms |
165548 KB |
Output is correct |
31 |
Correct |
469 ms |
166208 KB |
Output is correct |
32 |
Correct |
977 ms |
171700 KB |
Output is correct |
33 |
Correct |
749 ms |
165992 KB |
Output is correct |
34 |
Correct |
446 ms |
165504 KB |
Output is correct |
35 |
Correct |
410 ms |
166224 KB |
Output is correct |
36 |
Correct |
317 ms |
166604 KB |
Output is correct |
37 |
Correct |
1367 ms |
174604 KB |
Output is correct |
38 |
Correct |
545 ms |
174160 KB |
Output is correct |
39 |
Correct |
1010 ms |
165724 KB |
Output is correct |
40 |
Correct |
490 ms |
166228 KB |
Output is correct |
41 |
Correct |
258 ms |
166336 KB |
Output is correct |
42 |
Correct |
260 ms |
166848 KB |
Output is correct |
43 |
Correct |
266 ms |
166228 KB |
Output is correct |
44 |
Correct |
273 ms |
167000 KB |
Output is correct |
45 |
Correct |
320 ms |
167248 KB |
Output is correct |
46 |
Correct |
3 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4952 KB |
Output is correct |
48 |
Correct |
3 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
5212 KB |
Output is correct |
50 |
Correct |
3 ms |
4956 KB |
Output is correct |
51 |
Correct |
4 ms |
4952 KB |
Output is correct |
52 |
Correct |
1046 ms |
165612 KB |
Output is correct |
53 |
Correct |
459 ms |
166228 KB |
Output is correct |
54 |
Correct |
973 ms |
174420 KB |
Output is correct |
55 |
Correct |
723 ms |
165912 KB |
Output is correct |
56 |
Correct |
420 ms |
165972 KB |
Output is correct |
57 |
Correct |
404 ms |
155860 KB |
Output is correct |
58 |
Correct |
312 ms |
164804 KB |
Output is correct |
59 |
Correct |
1460 ms |
170916 KB |
Output is correct |
60 |
Correct |
602 ms |
172112 KB |
Output is correct |
61 |
Correct |
1032 ms |
160480 KB |
Output is correct |
62 |
Correct |
468 ms |
154716 KB |
Output is correct |
63 |
Correct |
2 ms |
4956 KB |
Output is correct |
64 |
Correct |
2 ms |
4956 KB |
Output is correct |
65 |
Correct |
2 ms |
4956 KB |
Output is correct |
66 |
Correct |
2 ms |
5212 KB |
Output is correct |
67 |
Correct |
3 ms |
4956 KB |
Output is correct |
68 |
Correct |
2 ms |
4956 KB |
Output is correct |
69 |
Correct |
2 ms |
4956 KB |
Output is correct |
70 |
Correct |
2 ms |
4956 KB |
Output is correct |
71 |
Correct |
3 ms |
4960 KB |
Output is correct |
72 |
Correct |
3 ms |
4956 KB |
Output is correct |
73 |
Correct |
2 ms |
4956 KB |
Output is correct |
74 |
Correct |
3 ms |
4956 KB |
Output is correct |
75 |
Correct |
3 ms |
4956 KB |
Output is correct |
76 |
Correct |
2 ms |
4956 KB |
Output is correct |
77 |
Correct |
3 ms |
4956 KB |
Output is correct |
78 |
Correct |
2 ms |
4952 KB |
Output is correct |
79 |
Correct |
1421 ms |
163660 KB |
Output is correct |
80 |
Correct |
880 ms |
170444 KB |
Output is correct |
81 |
Correct |
1258 ms |
169916 KB |
Output is correct |
82 |
Correct |
803 ms |
162848 KB |
Output is correct |
83 |
Correct |
482 ms |
162900 KB |
Output is correct |
84 |
Correct |
459 ms |
163292 KB |
Output is correct |
85 |
Correct |
319 ms |
163780 KB |
Output is correct |
86 |
Correct |
1518 ms |
168940 KB |
Output is correct |
87 |
Correct |
873 ms |
171440 KB |
Output is correct |
88 |
Correct |
1051 ms |
162640 KB |
Output is correct |
89 |
Correct |
571 ms |
163572 KB |
Output is correct |
90 |
Correct |
465 ms |
164236 KB |
Output is correct |
91 |
Correct |
504 ms |
164892 KB |
Output is correct |
92 |
Correct |
2 ms |
4952 KB |
Output is correct |
93 |
Correct |
2 ms |
4952 KB |
Output is correct |
94 |
Correct |
2 ms |
4996 KB |
Output is correct |
95 |
Correct |
2 ms |
4956 KB |
Output is correct |
96 |
Correct |
2 ms |
5196 KB |
Output is correct |
97 |
Correct |
2 ms |
4956 KB |
Output is correct |
98 |
Correct |
1408 ms |
167560 KB |
Output is correct |
99 |
Correct |
871 ms |
166056 KB |
Output is correct |
100 |
Correct |
1141 ms |
169808 KB |
Output is correct |
101 |
Correct |
762 ms |
164440 KB |
Output is correct |
102 |
Correct |
444 ms |
164736 KB |
Output is correct |
103 |
Correct |
413 ms |
164436 KB |
Output is correct |
104 |
Correct |
305 ms |
164808 KB |
Output is correct |
105 |
Correct |
1473 ms |
173600 KB |
Output is correct |
106 |
Correct |
875 ms |
172036 KB |
Output is correct |
107 |
Correct |
988 ms |
165204 KB |
Output is correct |
108 |
Correct |
533 ms |
163664 KB |
Output is correct |
109 |
Correct |
447 ms |
164432 KB |
Output is correct |
110 |
Correct |
443 ms |
165044 KB |
Output is correct |
111 |
Correct |
2 ms |
4956 KB |
Output is correct |
112 |
Correct |
2 ms |
4956 KB |
Output is correct |
113 |
Correct |
2 ms |
4956 KB |
Output is correct |
114 |
Correct |
2 ms |
5172 KB |
Output is correct |
115 |
Correct |
2 ms |
5168 KB |
Output is correct |
116 |
Correct |
965 ms |
163652 KB |
Output is correct |
117 |
Correct |
563 ms |
166224 KB |
Output is correct |
118 |
Correct |
1028 ms |
174420 KB |
Output is correct |
119 |
Correct |
763 ms |
165972 KB |
Output is correct |
120 |
Correct |
464 ms |
165460 KB |
Output is correct |
121 |
Correct |
452 ms |
166424 KB |
Output is correct |
122 |
Correct |
409 ms |
166860 KB |
Output is correct |
123 |
Correct |
1455 ms |
172880 KB |
Output is correct |
124 |
Correct |
884 ms |
171288 KB |
Output is correct |
125 |
Correct |
1012 ms |
164740 KB |
Output is correct |
126 |
Correct |
583 ms |
166236 KB |
Output is correct |
127 |
Correct |
526 ms |
166484 KB |
Output is correct |
128 |
Correct |
480 ms |
167252 KB |
Output is correct |
129 |
Correct |
470 ms |
167760 KB |
Output is correct |