Submission #683193

#TimeUsernameProblemLanguageResultExecution timeMemory
683193arnold518Sprinkler (JOI22_sprinkler)C++17
100 / 100
872 ms94360 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5+100; int N, Q; ll L, H[MAXN+10]; vector<int> adj[MAXN+10]; int par[MAXN+10]; ll val[MAXN+10][41]; void dfs(int now, int bef) { par[now]=bef; for(int nxt : adj[now]) { if(nxt==bef) continue; dfs(nxt, now); } } int main() { fill(&val[0][0], &val[0][0]+sizeof(val)/sizeof(ll), 1); scanf("%d%lld", &N, &L); for(int i=1; i<N; i++) { int u, v; scanf("%d%d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); } for(int i=1; i<=N; i++) sort(adj[i].begin(), adj[i].end()); for(int i=1; i<=N; i++) scanf("%lld", &H[i]); dfs(1, 0); for(int i=1; i<=50; i++) par[N+i]=N+i+1; par[1]=N+1; par[N+50]=0; scanf("%d", &Q); while(Q--) { int t; scanf("%d", &t); if(t==1) { int x, d, w; scanf("%d%d%d", &x, &d, &w); int now=x; while(now && d>=0) { if(d>0) (val[now][d-1]*=w)%=L; (val[now][d]*=w)%=L; d--; now=par[now]; } } else { int x; scanf("%d", &x); int now=x, d=0; ll ans=H[now]; while(now && d<=40) { (ans*=val[now][d])%=L; d++; now=par[now]; } printf("%lld\n", ans); } } }

Compilation message (stderr)

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d%lld", &N, &L);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
sprinkler.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   scanf("%d%d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~
sprinkler.cpp:39:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  for(int i=1; i<=N; i++) scanf("%lld", &H[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~
sprinkler.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
sprinkler.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d", &t);
      |   ~~~~~^~~~~~~~~~
sprinkler.cpp:53:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |    scanf("%d%d%d", &x, &d, &w);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:68:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
#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...