Submission #1239637

#TimeUsernameProblemLanguageResultExecution timeMemory
1239637countlessSprinkler (JOI22_sprinkler)C++20
100 / 100
643 ms93564 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define sp <<" "<< #define endl "\n" void solve() { ll n, MOD; cin >> n >> MOD; vector<vector<int>> adj(n + 42); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; u--, v--; adj[u].push_back(v); adj[v].push_back(u); } // cali4d nodes // permitir suficiente padres for (int i = n; i < n + 42; i++) { adj[i].push_back(i-1); adj[i-1].push_back(i); } // ! no senora no puedo mas ! // ok wtf am i doing vector<vector<ll>> mul(n + 42, vector<ll>(43, 1LL)); for(int i = 0; i < n; i++) cin >> mul[i][0]; vector<int> par(n + 42, -1); auto dfs = [&](auto &&dfs, int u, int p) -> void { for (auto &v : adj[u]) { if (v != p) { par[v] = u; dfs(dfs, v, u); } } }; // arise // ...or smth // aura farmer ahh sung jinwoo dfs(dfs, n + 41, -1); ll q; cin >> q; while (q--) { ll type; cin >> type; if (type == 1) { ll x, d, w; cin >> x >> d >> w; x--; ll at = x; while (d >= 0) { mul[at][d] = (mul[at][d] * w) % MOD; // nrm !(d&1) if (d) mul[at][d-1] = (mul[at][d-1] * w) % MOD; // par (d&1) at = par[at]; // cerr << at << endl; d--; } } else { ll x; cin >> x; x--; ll res = 1, d = 40, at = x; while (d >= 0) { // cerr << at+1 sp mul[at][40 - d] << endl; res = (res * mul[at][40 - d]) % MOD; at = par[at]; d--; } cout << res << endl; } } } signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int t = 1; // cin >> t; while (t--) solve(); }
#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...