Submission #896816

#TimeUsernameProblemLanguageResultExecution timeMemory
896816TAhmed33Sprinkler (JOI22_sprinkler)C++98
9 / 100
809 ms30508 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 25; vector <int> adj[MAXN]; int p[MAXN], h[MAXN], n, l, q; int lazy[MAXN]; void fix (int pos, int par) { p[pos] = par; for (int j = 0; j < (int)adj[pos].size(); j++) { if (adj[pos][j] == par) { adj[pos].erase(adj[pos].begin() + j); break; } } for (auto j : adj[pos]) { fix(j, pos); } } int main () { cin >> n >> l; for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) lazy[i] = 1; fix(1, -1); cin >> q; while (q--) { int t; cin >> t; if (t == 1) { int x, d, w; cin >> x >> d >> w; if (d == 0) { h[x] = (h[x] * 1ll * w) % l; } else if (d == 1) { if (p[x] != -1) { h[p[x]] = (h[p[x]] * 1ll * w) % l; lazy[x] = (lazy[x] * 1ll * w) % l; } else { lazy[x] = (lazy[x] * 1ll * w) % l; } } } else { int x; cin >> x; int z = h[x]; z = (z * 1ll * lazy[x]) % l; if (p[x] != -1) z = (z * 1ll * lazy[p[x]]) % l; cout << z << '\n'; } } }
#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...