제출 #972761

#제출 시각아이디문제언어결과실행 시간메모리
972761happy_nodeSprinkler (JOI22_sprinkler)C++17
3 / 100
4062 ms104784 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX=2e5+5; int N,L,Q; int A[MX], B[MX], H[MX]; vector<int> adj[MX]; int par[MX]; ll w[MX][50]; // w and w inverse void dfs(int v, int p) { par[v]=p; for(auto u:adj[v]) { if(u==p) continue; dfs(u,v); } } void upd(int v, int d, int x) { while(d>=0 && v!=0) { w[v][d]*=x; w[v][d]%=L; v=par[v]; d--; } } int que(int v) { int d=0,p=-1; ll res=1; while(d>=0 && v!=0) { for(int i=d;i<=40;i++) { if(par[v]!=0 && i-1>=d+1) continue; res*=w[v][i]; res%=L; } d++; p=v; v=par[v]; } return res; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); for(int i=0;i<MX;i++) for(int d=0;d<=41;d++) w[i][d]=1; cin>>N>>L; for(int i=0;i<N-1;i++) { cin>>A[i]>>B[i]; adj[A[i]].push_back(B[i]); adj[B[i]].push_back(A[i]); } for(int i=1;i<=N;i++) cin>>w[i][0]; dfs(1,0); cin>>Q; for(int i=1;i<=Q;i++) { int t; cin>>t; if(t==1) { int x,d,w; cin>>x>>d>>w; upd(x,d,w); } else { int x; cin>>x; cout<<que(x)<<'\n'; } } }

컴파일 시 표준 에러 (stderr) 메시지

sprinkler.cpp: In function 'int que(int)':
sprinkler.cpp:31:10: warning: variable 'p' set but not used [-Wunused-but-set-variable]
   31 |  int d=0,p=-1;
      |          ^
#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...