Submission #1208339

#TimeUsernameProblemLanguageResultExecution timeMemory
1208339salmonSprinkler (JOI22_sprinkler)C++20
12 / 100
654 ms54536 KiB
#include <bits/stdc++.h> using namespace std; int N,Q; long long int mod; int st[200100][45]; vector<int> adjlst[200100]; int parent[200100]; int lst[200100]; int cont = 1; void build(int it){ for(int i = 0; i < 45; i++) st[it][i] = 1; } void update(int it, int S, int E, int k){ for(int i = S; i <= E; i++) st[it][i] *= k; } int query(int it, int in){ return st[it][in]; } void dfs(int i, int p){ parent[i] = p; for(int j : adjlst[i]){ if(j == p) continue; dfs(j,i); } } int main(){ scanf(" %d",&N); scanf(" %lld",&mod); for(int i = 0; i < N - 1; i++){ int u,v; scanf(" %d",&u); scanf(" %d",&v); adjlst[u].push_back(v); adjlst[v].push_back(u); } for(int i = 1; i <= N; i++) scanf(" %d",&lst[i]); dfs(1,-1); for(int i = 1; i <= N; i++){ build(i); } scanf(" %d",&Q); for(int i = 0; i < Q; i++){ int h; scanf(" %d",&h); if(h == 1){ int X, D, W; scanf(" %d",&X); scanf(" %d",&D); scanf(" %d",&W); while(X != 1 && D >= 0){ update(X,D - 1, D, W); X = parent[X]; D -= 1; } if(X == 1 && D >= 0){ update(X,0,D,W); } } else{ int X; scanf(" %d",&X); int num = lst[X]; int D = 0; for(int i = 0; i < 41; i++){ num = query(X,D) * (long long int) num % mod; if(X == 1) break; D++; X = parent[X]; } printf("%d\n",num ); } } }

Compilation message (stderr)

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf(" %d",&N);
      |         ~~~~~^~~~~~~~~~
sprinkler.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf(" %lld",&mod);
      |         ~~~~~^~~~~~~~~~~~~~
sprinkler.cpp:43:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |                 scanf(" %d",&u);
      |                 ~~~~~^~~~~~~~~~
sprinkler.cpp:44:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |                 scanf(" %d",&v);
      |                 ~~~~~^~~~~~~~~~
sprinkler.cpp:50:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         for(int i = 1; i <= N; i++) scanf(" %d",&lst[i]);
      |                                     ~~~~~^~~~~~~~~~~~~~~
sprinkler.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         scanf(" %d",&Q);
      |         ~~~~~^~~~~~~~~~
sprinkler.cpp:63:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |                 scanf(" %d",&h);
      |                 ~~~~~^~~~~~~~~~
sprinkler.cpp:68:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |                         scanf(" %d",&X);
      |                         ~~~~~^~~~~~~~~~
sprinkler.cpp:69:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |                         scanf(" %d",&D);
      |                         ~~~~~^~~~~~~~~~
sprinkler.cpp:70:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |                         scanf(" %d",&W);
      |                         ~~~~~^~~~~~~~~~
sprinkler.cpp:85:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |                         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...