제출 #792154

#제출 시각아이디문제언어결과실행 시간메모리
792154winter0101Sprinkler (JOI22_sprinkler)C++14
9 / 100
698 ms97032 KiB
#include<bits/stdc++.h> using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) #define pil pair<int,long long> #define pll pair<long long,long long> #define eb emplace_back #define int long long const int maxn=2e5+9; int n; long long l; vector<int>a[maxn]; long long mul[maxn][41]; int dep[maxn]; int p[maxn]; long long h[maxn]; void dfs(int u,int par){ for (auto v:a[u]){ if(v==par)continue; p[v]=u; dep[v]=dep[u]+1; dfs(v,u); } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("temp.INP","r",stdin); //freopen("temp.OUT","w",stdout); cin>>n>>l; for1(i,1,n-1){ int u,v; cin>>u>>v; a[u].pb(v); a[v].pb(u); } dfs(1,0); for1(i,1,n)cin>>h[i]; for1(i,1,n){ for1(j,0,40){ mul[i][j]=1; } } int q; cin>>q; for1(i,1,q){ int t; cin>>t; if (t==1){ int x,dis; long long w; cin>>x>>dis>>w; int u=x; if (dis==0){ h[x]=(h[x]*w)%l; continue; } queue<int>ver; int v=x; for1(j,0,dis){ ver.push(v); if (p[v]!=0)v=p[v]; else break; } for1(j,0,dis){ mul[u][dis-j]=(mul[u][dis-j]*w)%l; int len=dis-j; //cout<<u<<" "<<len<<'\n'; while (!ver.empty()){ int t1=ver.front(); int dd=dep[t1]-dep[u]; //cout<<dd<<" "<<u<<'\n'; if (dd==len){ ver.pop(); } else if (dd<len)break; else if (dd>len){ h[t1]=(h[t1]*w)%l; //cerr<<t<<'\n'; ver.pop(); } } if (p[u]!=0)u=p[u]; } while (!ver.empty()){ int t1=ver.front(); ver.pop(); h[t1]=(h[t1]*w)%l; //cerr<<i<<" "<<t<<'\n'; } } else { int x; cin>>x; long long nw=h[x]; int u=x; for1(j,0,40){ nw=(nw*mul[u][j])%l; //cout<<u<<" "<<mul[u][j]<<" "<<j<<'\n'; if (p[u]!=0)u=p[u]; else break; } cout<<nw<<'\n'; } } //for1(i,1,n)cout<<h[i]<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...