/*input
4 7
1 2
2 3
3 4
1
1
1
1
11
1 2 1 2
1 1 0 2
2 1
2 2
2 3
2 4
1 4 10 2
2 1
2 2
2 3
2 4
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=5e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
int MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<P.f<<' '<<P.s;
return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?" ":"");
return out;
}
ll mult(ll a,ll b){
return a*b%MOD;
}
ll mypow(ll a,ll b){
a%=MOD;
if(a==0) return 0;
if(b<=0) return 1;
ll res=1LL;
while(b){
if(b&1) res=(res*a)%MOD;
a=(a*a)%MOD;
b>>=1;
}
return res;
}
vector<int> v[maxn];
int par[maxn];
void dfs(int u,int p){
par[u]=p;
for(int x:v[u]){
if(x==p) continue;
dfs(x,u);
}
}
ll upd[maxn][45];
int main(){
int n;
cin>>n>>MOD;
REP(i,n-1){
int a,b;
cin>>a>>b;
--a,--b;
v[a].pb(b),v[b].pb(a);
}
dfs(0,-1);
REP(i,n) REP(j,45) upd[i][j]=1;
REP(i,n) cin>>upd[i][0];
int q;
cin>>q;
while(q--){
int t;
cin>>t;
if(t==1){
int u,d,x;
cin>>u>>d>>x;
--u;
while(par[u]!=-1 and d){
upd[u][d]*=x;
upd[u][d-1]*=x;
upd[u][d]%=MOD,upd[u][d-1]%=MOD;
u=par[u];
--d;
}
REP(i,d+1) upd[u][i]*=x,upd[u][i]%=MOD;
}
else{
int u;
cin>>u;
--u;
ll ans=1;
int d=0;
while(u!=-1 and d<=40){
ans*=upd[u][d];
ans%=MOD;
u=par[u];
++d;
}
cout<<ans<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
12044 KB |
Output is correct |
4 |
Correct |
9 ms |
12580 KB |
Output is correct |
5 |
Correct |
10 ms |
12476 KB |
Output is correct |
6 |
Correct |
10 ms |
12488 KB |
Output is correct |
7 |
Correct |
10 ms |
12372 KB |
Output is correct |
8 |
Correct |
9 ms |
12500 KB |
Output is correct |
9 |
Correct |
8 ms |
11988 KB |
Output is correct |
10 |
Correct |
10 ms |
11988 KB |
Output is correct |
11 |
Correct |
8 ms |
12044 KB |
Output is correct |
12 |
Correct |
9 ms |
11988 KB |
Output is correct |
13 |
Correct |
8 ms |
12056 KB |
Output is correct |
14 |
Correct |
8 ms |
12064 KB |
Output is correct |
15 |
Correct |
7 ms |
12064 KB |
Output is correct |
16 |
Correct |
10 ms |
12044 KB |
Output is correct |
17 |
Correct |
9 ms |
12060 KB |
Output is correct |
18 |
Correct |
8 ms |
11988 KB |
Output is correct |
19 |
Correct |
7 ms |
11988 KB |
Output is correct |
20 |
Correct |
7 ms |
11988 KB |
Output is correct |
21 |
Correct |
9 ms |
11988 KB |
Output is correct |
22 |
Correct |
8 ms |
12048 KB |
Output is correct |
23 |
Correct |
9 ms |
12056 KB |
Output is correct |
24 |
Correct |
8 ms |
11988 KB |
Output is correct |
25 |
Correct |
8 ms |
12116 KB |
Output is correct |
26 |
Correct |
8 ms |
11988 KB |
Output is correct |
27 |
Correct |
8 ms |
11988 KB |
Output is correct |
28 |
Correct |
8 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
1459 ms |
101148 KB |
Output is correct |
3 |
Correct |
908 ms |
101700 KB |
Output is correct |
4 |
Correct |
1177 ms |
104312 KB |
Output is correct |
5 |
Correct |
1101 ms |
101024 KB |
Output is correct |
6 |
Correct |
930 ms |
99368 KB |
Output is correct |
7 |
Correct |
921 ms |
101712 KB |
Output is correct |
8 |
Correct |
859 ms |
99444 KB |
Output is correct |
9 |
Correct |
1365 ms |
105676 KB |
Output is correct |
10 |
Correct |
878 ms |
105860 KB |
Output is correct |
11 |
Correct |
1373 ms |
99592 KB |
Output is correct |
12 |
Correct |
855 ms |
98824 KB |
Output is correct |
13 |
Correct |
728 ms |
102092 KB |
Output is correct |
14 |
Correct |
722 ms |
102616 KB |
Output is correct |
15 |
Correct |
695 ms |
92104 KB |
Output is correct |
16 |
Correct |
736 ms |
100528 KB |
Output is correct |
17 |
Correct |
731 ms |
97696 KB |
Output is correct |
18 |
Correct |
9 ms |
11988 KB |
Output is correct |
19 |
Correct |
10 ms |
11988 KB |
Output is correct |
20 |
Correct |
7 ms |
12056 KB |
Output is correct |
21 |
Correct |
8 ms |
11988 KB |
Output is correct |
22 |
Correct |
8 ms |
12044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
1459 ms |
101148 KB |
Output is correct |
3 |
Correct |
908 ms |
101700 KB |
Output is correct |
4 |
Correct |
1177 ms |
104312 KB |
Output is correct |
5 |
Correct |
1101 ms |
101024 KB |
Output is correct |
6 |
Correct |
930 ms |
99368 KB |
Output is correct |
7 |
Correct |
921 ms |
101712 KB |
Output is correct |
8 |
Correct |
859 ms |
99444 KB |
Output is correct |
9 |
Correct |
1365 ms |
105676 KB |
Output is correct |
10 |
Correct |
878 ms |
105860 KB |
Output is correct |
11 |
Correct |
1373 ms |
99592 KB |
Output is correct |
12 |
Correct |
855 ms |
98824 KB |
Output is correct |
13 |
Correct |
728 ms |
102092 KB |
Output is correct |
14 |
Correct |
722 ms |
102616 KB |
Output is correct |
15 |
Correct |
695 ms |
92104 KB |
Output is correct |
16 |
Correct |
736 ms |
100528 KB |
Output is correct |
17 |
Correct |
731 ms |
97696 KB |
Output is correct |
18 |
Correct |
9 ms |
11988 KB |
Output is correct |
19 |
Correct |
10 ms |
11988 KB |
Output is correct |
20 |
Correct |
7 ms |
12056 KB |
Output is correct |
21 |
Correct |
8 ms |
11988 KB |
Output is correct |
22 |
Correct |
8 ms |
12044 KB |
Output is correct |
23 |
Correct |
8 ms |
12052 KB |
Output is correct |
24 |
Correct |
1443 ms |
101208 KB |
Output is correct |
25 |
Correct |
864 ms |
101236 KB |
Output is correct |
26 |
Correct |
1116 ms |
105860 KB |
Output is correct |
27 |
Correct |
1146 ms |
101040 KB |
Output is correct |
28 |
Correct |
986 ms |
101468 KB |
Output is correct |
29 |
Correct |
948 ms |
101332 KB |
Output is correct |
30 |
Correct |
872 ms |
101728 KB |
Output is correct |
31 |
Correct |
1516 ms |
104204 KB |
Output is correct |
32 |
Correct |
850 ms |
105036 KB |
Output is correct |
33 |
Correct |
1366 ms |
101152 KB |
Output is correct |
34 |
Correct |
843 ms |
101060 KB |
Output is correct |
35 |
Correct |
9 ms |
12116 KB |
Output is correct |
36 |
Correct |
11 ms |
11988 KB |
Output is correct |
37 |
Correct |
10 ms |
11988 KB |
Output is correct |
38 |
Correct |
9 ms |
11988 KB |
Output is correct |
39 |
Correct |
9 ms |
11988 KB |
Output is correct |
40 |
Correct |
8 ms |
12072 KB |
Output is correct |
41 |
Correct |
8 ms |
11988 KB |
Output is correct |
42 |
Correct |
7 ms |
12056 KB |
Output is correct |
43 |
Correct |
8 ms |
12052 KB |
Output is correct |
44 |
Correct |
7 ms |
12056 KB |
Output is correct |
45 |
Correct |
7 ms |
11988 KB |
Output is correct |
46 |
Correct |
8 ms |
12052 KB |
Output is correct |
47 |
Correct |
8 ms |
11988 KB |
Output is correct |
48 |
Correct |
8 ms |
12060 KB |
Output is correct |
49 |
Correct |
8 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11988 KB |
Output is correct |
2 |
Correct |
1445 ms |
102228 KB |
Output is correct |
3 |
Correct |
1334 ms |
101660 KB |
Output is correct |
4 |
Correct |
1277 ms |
101544 KB |
Output is correct |
5 |
Correct |
1133 ms |
98172 KB |
Output is correct |
6 |
Correct |
951 ms |
98000 KB |
Output is correct |
7 |
Correct |
931 ms |
98312 KB |
Output is correct |
8 |
Correct |
835 ms |
98684 KB |
Output is correct |
9 |
Correct |
1477 ms |
101432 KB |
Output is correct |
10 |
Correct |
1193 ms |
102488 KB |
Output is correct |
11 |
Correct |
1340 ms |
97900 KB |
Output is correct |
12 |
Correct |
1078 ms |
98440 KB |
Output is correct |
13 |
Correct |
840 ms |
99112 KB |
Output is correct |
14 |
Correct |
870 ms |
100112 KB |
Output is correct |
15 |
Correct |
8 ms |
11988 KB |
Output is correct |
16 |
Correct |
8 ms |
11988 KB |
Output is correct |
17 |
Correct |
9 ms |
12056 KB |
Output is correct |
18 |
Correct |
8 ms |
12068 KB |
Output is correct |
19 |
Correct |
7 ms |
11984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
1435 ms |
103080 KB |
Output is correct |
3 |
Correct |
1283 ms |
101236 KB |
Output is correct |
4 |
Correct |
1171 ms |
102356 KB |
Output is correct |
5 |
Correct |
1213 ms |
99744 KB |
Output is correct |
6 |
Correct |
1016 ms |
99928 KB |
Output is correct |
7 |
Correct |
950 ms |
99640 KB |
Output is correct |
8 |
Correct |
828 ms |
100032 KB |
Output is correct |
9 |
Correct |
1500 ms |
104976 KB |
Output is correct |
10 |
Correct |
1369 ms |
102820 KB |
Output is correct |
11 |
Correct |
1421 ms |
100676 KB |
Output is correct |
12 |
Correct |
1101 ms |
98820 KB |
Output is correct |
13 |
Correct |
858 ms |
99932 KB |
Output is correct |
14 |
Correct |
860 ms |
100340 KB |
Output is correct |
15 |
Correct |
8 ms |
11988 KB |
Output is correct |
16 |
Correct |
8 ms |
12056 KB |
Output is correct |
17 |
Correct |
7 ms |
12040 KB |
Output is correct |
18 |
Correct |
8 ms |
12076 KB |
Output is correct |
19 |
Correct |
8 ms |
12056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
12044 KB |
Output is correct |
4 |
Correct |
9 ms |
12580 KB |
Output is correct |
5 |
Correct |
10 ms |
12476 KB |
Output is correct |
6 |
Correct |
10 ms |
12488 KB |
Output is correct |
7 |
Correct |
10 ms |
12372 KB |
Output is correct |
8 |
Correct |
9 ms |
12500 KB |
Output is correct |
9 |
Correct |
8 ms |
11988 KB |
Output is correct |
10 |
Correct |
10 ms |
11988 KB |
Output is correct |
11 |
Correct |
8 ms |
12044 KB |
Output is correct |
12 |
Correct |
9 ms |
11988 KB |
Output is correct |
13 |
Correct |
8 ms |
12056 KB |
Output is correct |
14 |
Correct |
8 ms |
12064 KB |
Output is correct |
15 |
Correct |
7 ms |
12064 KB |
Output is correct |
16 |
Correct |
10 ms |
12044 KB |
Output is correct |
17 |
Correct |
9 ms |
12060 KB |
Output is correct |
18 |
Correct |
8 ms |
11988 KB |
Output is correct |
19 |
Correct |
7 ms |
11988 KB |
Output is correct |
20 |
Correct |
7 ms |
11988 KB |
Output is correct |
21 |
Correct |
9 ms |
11988 KB |
Output is correct |
22 |
Correct |
8 ms |
12048 KB |
Output is correct |
23 |
Correct |
9 ms |
12056 KB |
Output is correct |
24 |
Correct |
8 ms |
11988 KB |
Output is correct |
25 |
Correct |
8 ms |
12116 KB |
Output is correct |
26 |
Correct |
8 ms |
11988 KB |
Output is correct |
27 |
Correct |
8 ms |
11988 KB |
Output is correct |
28 |
Correct |
8 ms |
11988 KB |
Output is correct |
29 |
Correct |
6 ms |
11988 KB |
Output is correct |
30 |
Correct |
1459 ms |
101148 KB |
Output is correct |
31 |
Correct |
908 ms |
101700 KB |
Output is correct |
32 |
Correct |
1177 ms |
104312 KB |
Output is correct |
33 |
Correct |
1101 ms |
101024 KB |
Output is correct |
34 |
Correct |
930 ms |
99368 KB |
Output is correct |
35 |
Correct |
921 ms |
101712 KB |
Output is correct |
36 |
Correct |
859 ms |
99444 KB |
Output is correct |
37 |
Correct |
1365 ms |
105676 KB |
Output is correct |
38 |
Correct |
878 ms |
105860 KB |
Output is correct |
39 |
Correct |
1373 ms |
99592 KB |
Output is correct |
40 |
Correct |
855 ms |
98824 KB |
Output is correct |
41 |
Correct |
728 ms |
102092 KB |
Output is correct |
42 |
Correct |
722 ms |
102616 KB |
Output is correct |
43 |
Correct |
695 ms |
92104 KB |
Output is correct |
44 |
Correct |
736 ms |
100528 KB |
Output is correct |
45 |
Correct |
731 ms |
97696 KB |
Output is correct |
46 |
Correct |
9 ms |
11988 KB |
Output is correct |
47 |
Correct |
10 ms |
11988 KB |
Output is correct |
48 |
Correct |
7 ms |
12056 KB |
Output is correct |
49 |
Correct |
8 ms |
11988 KB |
Output is correct |
50 |
Correct |
8 ms |
12044 KB |
Output is correct |
51 |
Correct |
8 ms |
12052 KB |
Output is correct |
52 |
Correct |
1443 ms |
101208 KB |
Output is correct |
53 |
Correct |
864 ms |
101236 KB |
Output is correct |
54 |
Correct |
1116 ms |
105860 KB |
Output is correct |
55 |
Correct |
1146 ms |
101040 KB |
Output is correct |
56 |
Correct |
986 ms |
101468 KB |
Output is correct |
57 |
Correct |
948 ms |
101332 KB |
Output is correct |
58 |
Correct |
872 ms |
101728 KB |
Output is correct |
59 |
Correct |
1516 ms |
104204 KB |
Output is correct |
60 |
Correct |
850 ms |
105036 KB |
Output is correct |
61 |
Correct |
1366 ms |
101152 KB |
Output is correct |
62 |
Correct |
843 ms |
101060 KB |
Output is correct |
63 |
Correct |
9 ms |
12116 KB |
Output is correct |
64 |
Correct |
11 ms |
11988 KB |
Output is correct |
65 |
Correct |
10 ms |
11988 KB |
Output is correct |
66 |
Correct |
9 ms |
11988 KB |
Output is correct |
67 |
Correct |
9 ms |
11988 KB |
Output is correct |
68 |
Correct |
8 ms |
12072 KB |
Output is correct |
69 |
Correct |
8 ms |
11988 KB |
Output is correct |
70 |
Correct |
7 ms |
12056 KB |
Output is correct |
71 |
Correct |
8 ms |
12052 KB |
Output is correct |
72 |
Correct |
7 ms |
12056 KB |
Output is correct |
73 |
Correct |
7 ms |
11988 KB |
Output is correct |
74 |
Correct |
8 ms |
12052 KB |
Output is correct |
75 |
Correct |
8 ms |
11988 KB |
Output is correct |
76 |
Correct |
8 ms |
12060 KB |
Output is correct |
77 |
Correct |
8 ms |
11988 KB |
Output is correct |
78 |
Correct |
8 ms |
11988 KB |
Output is correct |
79 |
Correct |
1445 ms |
102228 KB |
Output is correct |
80 |
Correct |
1334 ms |
101660 KB |
Output is correct |
81 |
Correct |
1277 ms |
101544 KB |
Output is correct |
82 |
Correct |
1133 ms |
98172 KB |
Output is correct |
83 |
Correct |
951 ms |
98000 KB |
Output is correct |
84 |
Correct |
931 ms |
98312 KB |
Output is correct |
85 |
Correct |
835 ms |
98684 KB |
Output is correct |
86 |
Correct |
1477 ms |
101432 KB |
Output is correct |
87 |
Correct |
1193 ms |
102488 KB |
Output is correct |
88 |
Correct |
1340 ms |
97900 KB |
Output is correct |
89 |
Correct |
1078 ms |
98440 KB |
Output is correct |
90 |
Correct |
840 ms |
99112 KB |
Output is correct |
91 |
Correct |
870 ms |
100112 KB |
Output is correct |
92 |
Correct |
8 ms |
11988 KB |
Output is correct |
93 |
Correct |
8 ms |
11988 KB |
Output is correct |
94 |
Correct |
9 ms |
12056 KB |
Output is correct |
95 |
Correct |
8 ms |
12068 KB |
Output is correct |
96 |
Correct |
7 ms |
11984 KB |
Output is correct |
97 |
Correct |
7 ms |
11988 KB |
Output is correct |
98 |
Correct |
1435 ms |
103080 KB |
Output is correct |
99 |
Correct |
1283 ms |
101236 KB |
Output is correct |
100 |
Correct |
1171 ms |
102356 KB |
Output is correct |
101 |
Correct |
1213 ms |
99744 KB |
Output is correct |
102 |
Correct |
1016 ms |
99928 KB |
Output is correct |
103 |
Correct |
950 ms |
99640 KB |
Output is correct |
104 |
Correct |
828 ms |
100032 KB |
Output is correct |
105 |
Correct |
1500 ms |
104976 KB |
Output is correct |
106 |
Correct |
1369 ms |
102820 KB |
Output is correct |
107 |
Correct |
1421 ms |
100676 KB |
Output is correct |
108 |
Correct |
1101 ms |
98820 KB |
Output is correct |
109 |
Correct |
858 ms |
99932 KB |
Output is correct |
110 |
Correct |
860 ms |
100340 KB |
Output is correct |
111 |
Correct |
8 ms |
11988 KB |
Output is correct |
112 |
Correct |
8 ms |
12056 KB |
Output is correct |
113 |
Correct |
7 ms |
12040 KB |
Output is correct |
114 |
Correct |
8 ms |
12076 KB |
Output is correct |
115 |
Correct |
8 ms |
12056 KB |
Output is correct |
116 |
Correct |
1414 ms |
98760 KB |
Output is correct |
117 |
Correct |
1280 ms |
101492 KB |
Output is correct |
118 |
Correct |
1265 ms |
105024 KB |
Output is correct |
119 |
Correct |
1266 ms |
101028 KB |
Output is correct |
120 |
Correct |
1040 ms |
100608 KB |
Output is correct |
121 |
Correct |
1054 ms |
101500 KB |
Output is correct |
122 |
Correct |
910 ms |
101548 KB |
Output is correct |
123 |
Correct |
1550 ms |
104732 KB |
Output is correct |
124 |
Correct |
1389 ms |
104168 KB |
Output is correct |
125 |
Correct |
1502 ms |
99464 KB |
Output is correct |
126 |
Correct |
1376 ms |
101184 KB |
Output is correct |
127 |
Correct |
1236 ms |
101896 KB |
Output is correct |
128 |
Correct |
1097 ms |
101580 KB |
Output is correct |
129 |
Correct |
1016 ms |
102812 KB |
Output is correct |