Submission #704474

#TimeUsernameProblemLanguageResultExecution timeMemory
704474piOOESprinkler (JOI22_sprinkler)C++17
0 / 100
968 ms56072 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, MOD; cin >> n >> MOD; vector<vector<int>> adj(n); for (int i = 1; i < n; ++i) { int a, b; cin >> a >> b; a -= 1, b -= 1; adj[a].push_back(b); adj[b].push_back(a); } vector<int> parent(n, -1), depth(n); auto dfs = [&](auto self, int v) -> void { for (int to : adj[v]) { if (to != parent[v]) { depth[to] = depth[v] + 1; parent[to] = v; self(self, to); } } }; dfs(dfs, 0); vector<int> h(n); for (int &x : h) { cin >> x; } int q; cin >> q; constexpr int maxD = 43; vector<array<int, maxD>> kek(n); for (int i = 0; i < n; ++i) { fill(kek[i].begin(), kek[i].end(), 1); } for (int i = 0; i < q; ++i) { int t, v; cin >> t >> v; v -= 1; if (t == 1) { int dist; ll weight; cin >> dist >> weight; while (v != 0 && dist > 0) { kek[v][dist] = weight * kek[v][dist] % MOD; kek[v][dist - 1] = weight * kek[v][dist - 1] % MOD; v = parent[v]; dist -= 1; } for (int j = 0; j <= dist; ++j) { kek[v][j] = kek[v][j] * weight % MOD; } } else { int dist = 0, ans = h[v]; while (v != -1 && dist <= maxD * 2) { ans = 1LL * ans * kek[v][dist] % MOD; v = parent[v]; dist += 1; } cout << ans << '\n'; } } return 0; }
#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...