제출 #892353

#제출 시각아이디문제언어결과실행 시간메모리
892353vjudge1Sprinkler (JOI22_sprinkler)C++17
12 / 100
210 ms25008 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define size(x) (int)x.size() template<class S, class T> bool chmin(S &a, const T &b) { return a > b && (a = b) == b; } template<class S, class T> bool chmax(S &a, const T &b) { return a < b && (a = b) == b; } const int inf = 1e9 + 7; const int INF = 1e18 + 7; const int mod = 998244353; const int N = 2e5 + 1; int n, l; vector<int> g[N], p(N), h(N), cf(N, 1); void dfs(int v, int parent, int d, int bound, int w) { h[v] *= w; h[v] %= l; if (d == bound) return; for (int to : g[v]) { if (to != parent) { dfs(to, v, d + 1, bound, w); } } } void walk(int v, int parent) { p[v] = parent; for (int to : g[v]) { if (to != parent) { walk(to, v); } } } signed main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> l; for (int i = 1; i < n; ++i) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } for (int i = 1; i <= n; ++i) { cin >> h[i]; } int q; cin >> q; if (n <= 1000 && q <= 1000) { while (q--) { int t; cin >> t; if (t == 1) { int v, d, w; cin >> v >> d >> w; dfs(v, -1, 0, d, w); } else { int v; cin >> v; cout << h[v] << '\n'; } } } else { walk(1, 0); while (q--) { int t; cin >> t; if (t == 1) { int v, d, w; cin >> v >> d >> w; if (d == 0) { h[v] *= w; h[v] %= l; } else { h[p[v]] *= w; h[p[v]] %= l; h[v] *= w; h[v] %= l; cf[v] *= w; cf[v] %= l; } } else { int v; cin >> v; cout << h[v] * cf[p[v]] % l << '\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...