Submission #792178

#TimeUsernameProblemLanguageResultExecution timeMemory
792178winter0101Sprinkler (JOI22_sprinkler)C++14
100 / 100
984 ms103792 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); } } void update(int x,int d,long long w){ if (x==0||d==-1)return; update(p[x],d-1,w); if (x==1){ for1(i,0,d)mul[x][i]=(mul[x][i]*w)%l; } else { mul[x][d]=(mul[x][d]*w)%l; if (d)mul[x][d-1]=(mul[x][d-1]*w)%l; } } 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; update(x,dis,w); } 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'; } } }
#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...