#include<iostream>
#include<cstdlib>
#include<vector>
#include<cassert>
#define ll long long
using namespace std;
int n,q,a,b,c,ojc[200005],d,ojc2[81];
ll L,tab[200005],x;
ll t[200005][42];
ll f[200005][81];
ll p[200005];
vector<int> v[200005];
vector<int> v2[42];
void DFS(int x,int f){
ojc[x]=f;
for(auto i:v[x]) if(i!=f) DFS(i,x);
}
void dod2(int x,int p,int k,ll z){
assert(k==(p+1));
t[x][p]*=z,t[x][p]%=L;
}
void dod(int x,int k,ll z){
//od 0 do k
p[x]*=z,p[x]%=L;
for(auto u:v2[k])
f[x][u]*=z,f[x][u]%=L;
}
int main(){
ios_base::sync_with_stdio(0);
cin>>n>>L;
for(int i=1;i<n;i++){
cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
}
for(int i=1;i<=n;i++){
for(int u=0;u<=41;u++) t[i][u]=1;
for(int u=0;u<80;u++) f[i][u]=1;
p[i]=1;
cin>>tab[i];
}
for(int u=1;u<=63;u++) ojc2[u]=u>>1;
ojc2[64]=0;
for(int u=65;u<=78;u++) ojc2[u]=((u-63)>>1)+63; //fenwick liczy odleglosci od 1
for(int u=1;u<=32;u++){
int p=1,k=32,m=1;
while(true){
if(k==u){
v2[u].push_back(m);
break;
}
if(p>u) break;
if(u>((p+k)>>1)){
v2[u].push_back(m*2);
m=m*2+1;
p=((p+k)>>1)+1;
}else{
m=m*2;
k=((p+k)>>1);
}
}
}
DFS(1,-1);
//return 0;
//cerr<<v2[0].size()<<" rozmiar\n";
cin>>q;
for(int i=0;i<q;i++){
cin>>a;
if(a==2){
cin>>b;
d=0,c=b;
ll wyn=tab[b];
//cerr<<wyn<<"\n";
wyn*=p[c];
wyn%=L;
while(true){
wyn*=t[c][d];
wyn%=L;
if(d!=0){
wyn*=t[c][d-1];
wyn%=L;
if(d<=32)
a=d+31;
else
a=d+38;
wyn*=f[c][a];
wyn%=L;
//cerr<<"f["<<c<<"]["<<a<<"]="<<f[c][a]<<"\n";
while(a!=0){
a=ojc2[a];
//cerr<<"f["<<c<<"]["<<a<<"]="<<f[c][a]<<"\n";
wyn*=f[c][a];
wyn%=L;
}
}
c=ojc[c];
if(c==-1) break;
d++;
if(d>40) break;
}
cout<<wyn<<"\n";
}else{
cin>>b>>c>>x;
d=0;
while(true){
if(b==-1 || d>c) break;
if(b!=1 && c!=d){
//cerr<<b<<" "<<c-d-1<<"\n";
dod2(b,c-d-1,c-d,x);
}else{
//cerr<<b<<" "<<c<<"-"<<d<<" "<<" drzewo\n";
dod(b,c-d,x);
}
b=ojc[b];
d++;
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5972 KB |
Output is correct |
5 |
Correct |
7 ms |
6100 KB |
Output is correct |
6 |
Incorrect |
6 ms |
6100 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2197 ms |
211368 KB |
Output is correct |
3 |
Correct |
619 ms |
208160 KB |
Output is correct |
4 |
Correct |
1483 ms |
212536 KB |
Output is correct |
5 |
Correct |
1243 ms |
209732 KB |
Output is correct |
6 |
Correct |
733 ms |
209700 KB |
Output is correct |
7 |
Correct |
662 ms |
210040 KB |
Output is correct |
8 |
Correct |
483 ms |
210512 KB |
Output is correct |
9 |
Correct |
2420 ms |
215616 KB |
Output is correct |
10 |
Correct |
530 ms |
212080 KB |
Output is correct |
11 |
Correct |
1965 ms |
211372 KB |
Output is correct |
12 |
Correct |
521 ms |
208100 KB |
Output is correct |
13 |
Correct |
279 ms |
208828 KB |
Output is correct |
14 |
Correct |
291 ms |
208848 KB |
Output is correct |
15 |
Correct |
292 ms |
208800 KB |
Output is correct |
16 |
Correct |
312 ms |
208716 KB |
Output is correct |
17 |
Correct |
305 ms |
209292 KB |
Output is correct |
18 |
Correct |
3 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2197 ms |
211368 KB |
Output is correct |
3 |
Correct |
619 ms |
208160 KB |
Output is correct |
4 |
Correct |
1483 ms |
212536 KB |
Output is correct |
5 |
Correct |
1243 ms |
209732 KB |
Output is correct |
6 |
Correct |
733 ms |
209700 KB |
Output is correct |
7 |
Correct |
662 ms |
210040 KB |
Output is correct |
8 |
Correct |
483 ms |
210512 KB |
Output is correct |
9 |
Correct |
2420 ms |
215616 KB |
Output is correct |
10 |
Correct |
530 ms |
212080 KB |
Output is correct |
11 |
Correct |
1965 ms |
211372 KB |
Output is correct |
12 |
Correct |
521 ms |
208100 KB |
Output is correct |
13 |
Correct |
279 ms |
208828 KB |
Output is correct |
14 |
Correct |
291 ms |
208848 KB |
Output is correct |
15 |
Correct |
292 ms |
208800 KB |
Output is correct |
16 |
Correct |
312 ms |
208716 KB |
Output is correct |
17 |
Correct |
305 ms |
209292 KB |
Output is correct |
18 |
Correct |
3 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 |
4948 KB |
Output is correct |
24 |
Correct |
2107 ms |
211400 KB |
Output is correct |
25 |
Correct |
521 ms |
208204 KB |
Output is correct |
26 |
Correct |
1512 ms |
213868 KB |
Output is correct |
27 |
Correct |
1207 ms |
209792 KB |
Output is correct |
28 |
Correct |
761 ms |
209908 KB |
Output is correct |
29 |
Correct |
665 ms |
209960 KB |
Output is correct |
30 |
Correct |
504 ms |
210592 KB |
Output is correct |
31 |
Correct |
2319 ms |
214372 KB |
Output is correct |
32 |
Correct |
546 ms |
212292 KB |
Output is correct |
33 |
Correct |
2045 ms |
211288 KB |
Output is correct |
34 |
Correct |
536 ms |
208176 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
3 ms |
4948 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
3 ms |
4948 KB |
Output is correct |
44 |
Correct |
3 ms |
4948 KB |
Output is correct |
45 |
Correct |
3 ms |
4948 KB |
Output is correct |
46 |
Correct |
3 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 |
4 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
2353 ms |
212936 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
2523 ms |
214124 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5972 KB |
Output is correct |
5 |
Correct |
7 ms |
6100 KB |
Output is correct |
6 |
Incorrect |
6 ms |
6100 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |