Submission #1015943

#TimeUsernameProblemLanguageResultExecution timeMemory
1015943TAhmed33Sprinkler (JOI22_sprinkler)C++98
0 / 100
4 ms5212 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int B = 40; const int MAXN = 2e5 + 40 + 25; int n, l, p[MAXN]; vector <int> adj[MAXN]; int dp[MAXN][B + 1], dep[MAXN]; int mul (int x, int y) { return (x * 1ll * y) % l; } int h[MAXN]; void dfs (int pos, int par) { p[pos] = par; for (auto j : adj[pos]) { if (j != par) { dep[j] = 1 + dep[pos]; dfs(j, pos); } } } void solve () { cin >> n >> l; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; adj[x].push_back(y); adj[y].push_back(x); } dfs(1, 0); for (int i = 1; i <= n; i++) { cin >> h[i]; } p[1] = n + 1; for (int i = n + 2; i <= n + 40; i++) { p[i - 1] = i; } for (int i = 1; i <= n + 40; i++) { for (int j = 0; j <= B; j++) { dp[i][j] = 1; } } int q; cin >> q; while (q--) { int t; cin >> t; if (t == 1) { int x, d, w; cin >> x >> d >> w; for (int i = d; i >= 0; i--) { dp[x][i] = mul(dp[x][i], w); if (i) { dp[x][i - 1] = mul(dp[x][i - 1], w); } x = p[x]; } } else { int x; cin >> x; int ret = h[x]; for (int i = 0; i <= B; i++) { ret = mul(ret, dp[x][i]); if (p[x]) { x = p[x]; } } cout << ret << '\n'; } } } signed main () { #ifndef ONLINE_JUDGE freopen("input_file", "r", stdin); freopen("output_file", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); int tc = 1; //cin >> tc; while (tc--) solve(); }

Compilation message (stderr)

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen("input_file", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("output_file", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...