Submission #954051

#TimeUsernameProblemLanguageResultExecution timeMemory
954051PringSprinkler (JOI22_sprinkler)C++17
3 / 100
370 ms22272 KiB
#include <bits/stdc++.h> using namespace std; #ifdef MIKU string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m"; #define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x) void dout() { cout << dbrs << endl; } template <typename T, typename ...U> void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); } #else #define debug(...) 39 #endif #define int long long #define fs first #define sc second #define mp make_pair #define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++) typedef pair<int, int> pii; const int MXN = 200005, MXD = 40; int n, q, mod, h[MXN]; vector<int> edge[MXN]; namespace SB1 { void DFS(int id, int par, int rst, int w) { h[id] = h[id] * w % mod; if (rst == 0) return; for (auto &i : edge[id]) { if (i == par) continue; DFS(i, id, rst - 1, w); } } void solve() { cin >> q; while (q--) { int t, x, d, w; cin >> t; if (t == 1) { cin >> x >> d >> w; DFS(x, 0, d, w); } else { cin >> x; cout << h[x] << '\n'; } } } } namespace SB4 { int p[MXN]; int d[MXN]; void DFS(int id, int par) { p[id] = par; for (auto &i : edge[id]) { if (i == par) continue; DFS(i, id); } } void modify(int x, int r) { int now = x; for (int i = r; i >= 0; i--) { d[now] = max(d[now], i); if (p[now] == 0) return; now = p[now]; } } bool alive(int x) { int now = x; FOR(i, 0, 41) { if (d[now] > i) return false; if (p[now] == 0) return true; now = p[now]; } return true; } void solve() { DFS(1, 0); fill(d + 1, d + n + 1, -1); cin >> q; while (q--) { int t, x, d, w; cin >> t; if (t == 1) { cin >> x >> d >> w; modify(x, d); } else { cin >> x; cout << (alive(x) ? h[x] : 0) << '\n'; } } } } void miku() { int x, y; cin >> n >> mod; FOR(i, 1, n) { cin >> x >> y; edge[x].push_back(y); edge[y].push_back(x); } FOR(i, 1, n + 1) cin >> h[i]; if (n <= 1000) SB1::solve(); else SB4::solve(); } int32_t main() { cin.tie(0) -> sync_with_stdio(false); cin.exceptions(cin.failbit); miku(); 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...