Submission #661283

#TimeUsernameProblemLanguageResultExecution timeMemory
661283Alex_tz307Sprinkler (JOI22_sprinkler)C++17
100 / 100
1530 ms70072 KiB
#include <bits/stdc++.h> using namespace std; const int kN = 2e5; const int kD = 40; int par[1 + kN + kD]; vector<int> g[1 + kN + kD]; void multSelf(int &x, int y, int mod) { x = (int64_t)x * y % mod; } void dfs(int u) { for (int v : g[u]) { if (v != par[u]) { par[v] = u; dfs(v); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, l; cin >> n >> l; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; g[u].emplace_back(v); g[v].emplace_back(u); } g[n + 1].emplace_back(1); for (int i = n + 2; i <= n + kD; ++i) { g[i].emplace_back(i - 1); } dfs(n + kD); vector<int> h(n + 1); for (int i = 1; i <= n; ++i) { cin >> h[i]; } vector<vector<int>> coef(1 + n + kD, vector<int>(1 + kD, 1)); int q; cin >> q; for (int i = 1; i <= q; ++i) { int t; cin >> t; if (t == 1) { int x, d, w; cin >> x >> d >> w; int node = x, curr = d; while (curr >= 0) { multSelf(coef[node][curr], w, l); node = par[node]; curr -= 1; } node = x, curr = d - 1; while (curr >= 0) { multSelf(coef[node][curr], w, l); node = par[node]; curr -= 1; } } else { int x; cin >> x; int res = h[x]; for (int d = 0; d <= kD; ++d) { multSelf(res, coef[x][d], l); x = par[x]; } cout << res << '\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...