Submission #589582

#TimeUsernameProblemLanguageResultExecution timeMemory
589582GioChkhaidzeSprinkler (JOI22_sprinkler)C++14
100 / 100
789 ms103276 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back using namespace std; const int N = 2e5 + 55; const int K = 44; int n, q, pr[N]; ll D[N][K], h[N], L; vector < int > v[N]; void dfs(int x, int p) { pr[x] = p; for (int i = 0; i < v[x].size(); ++i) { int to = v[x][i]; if (to == p) continue; dfs(to, x); } } main () { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> L; for (int i = 1; i < n; ++i) { int a, b; cin >> a >> b; v[a].pb(b); v[b].pb(a); } dfs(1, 0); int st = 0; for (int i = n + 1; i <= n + 40; ++i) { pr[st] = i; st = i; } for (int i = 0; i <= n + 40; ++i) { for (int j = 0; j <= 40; ++j) { D[i][j] = 1; } } for (int i = 1; i <= n; ++i) { cin >> h[i]; } cin >> q; for (int i = 1; i <= q; ++i) { int tp, x; cin >> tp; if (tp == 1) { ll d, W; cin >> x >> d >> W; for (int j = d; j >= 0; --j) { D[x][j] = (D[x][j] * W) % L; if (0 < j) { D[x][j - 1] = (D[x][j - 1] * W) % L; } D[x][j] %= L; x = pr[x]; } } else if (tp == 2) { cin >> x; ll ans = h[x]; for (int j = 0; j <= 40; ++j) { ans = (ans * D[x][j]) % L; x = pr[x]; } cout << ans << "\n"; } } }

Compilation message (stderr)

sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (int i = 0; i < v[x].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~
sprinkler.cpp: At global scope:
sprinkler.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main () {
      | ^~~~
#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...